package com.ktgj.flight.common.spring;

import com.alibaba.fastjson.JSON;
import com.ktgj.common.core.enums.EnumHelper;
import com.ktgj.common.core.utils.DateUtils;
import com.ktgj.common.core.utils.HttpClientUtil;
import com.ktgj.common.core.utils.StringUtils;
import com.ktgj.common.core.utils.reflect.ReflectUtils;
import com.ktgj.common.spring.entity.iata.iata_airshoppingrq.AffinityRequestType;
import com.ktgj.common.spring.entity.iata.iata_airshoppingrq.CountryType;
import com.ktgj.common.spring.entity.iata.iata_airshoppingrq.CurParameterType;
import com.ktgj.common.spring.entity.iata.iata_airshoppingrq.DestArrivalCriteriaType;
import com.ktgj.common.spring.entity.iata.iata_airshoppingrq.FlightRequestType;
import com.ktgj.common.spring.entity.iata.iata_airshoppingrq.KeyValuePropertyType;
import com.ktgj.common.spring.entity.iata.iata_airshoppingrq.MessageDocType;
import com.ktgj.common.spring.entity.iata.iata_airshoppingrq.OriginDepCriteriaType;
import com.ktgj.common.spring.entity.iata.iata_airshoppingrq.OriginDestCriteriaType;
import com.ktgj.common.spring.entity.iata.iata_airshoppingrq.POSType;
import com.ktgj.common.spring.entity.iata.iata_airshoppingrq.RequestType;
import com.ktgj.common.spring.entity.iata.iata_airshoppingrq.ResponseParametersType;
import com.ktgj.common.spring.entity.iata.iata_airshoppingrq.*;
import com.ktgj.common.spring.entity.iata.iata_airshoppingrs.DataListsType;
import com.ktgj.common.spring.entity.iata.iata_airshoppingrs.FareComponentType;
import com.ktgj.common.spring.entity.iata.iata_airshoppingrs.FareDetailType;
import com.ktgj.common.spring.entity.iata.iata_airshoppingrs.FareRuleType;
import com.ktgj.common.spring.entity.iata.iata_airshoppingrs.OfferItemType;
import com.ktgj.common.spring.entity.iata.iata_airshoppingrs.PaxSegmentType;
import com.ktgj.common.spring.entity.iata.iata_airshoppingrs.*;
import com.ktgj.common.spring.entity.iata.iata_airshoppingrs.PenaltyType;
import com.ktgj.common.spring.entity.iata.iata_airshoppingrs.TaxType;
import com.ktgj.common.spring.entity.iata.iata_ordercancelrq.IATAOrderCancelRQ;
import com.ktgj.common.spring.entity.iata.iata_ordercancelrq.PointofSaleType;
import com.ktgj.common.spring.entity.iata.iata_ordercancelrs.IATAOrderCancelRS;
import com.ktgj.common.spring.entity.iata.iata_orderchangerq.ChangeOrderType;
import com.ktgj.common.spring.entity.iata.iata_orderchangerq.IATAOrderChangeRQ;
import com.ktgj.common.spring.entity.iata.iata_orderchangerq.UpdateOrderItemType;
import com.ktgj.common.spring.entity.iata.iata_ordercreaterq.*;
import com.ktgj.common.spring.entity.iata.iata_orderreshoprq.*;
import com.ktgj.common.spring.entity.iata.iata_orderreshoprs.IATAOrderReshopRS;
import com.ktgj.common.spring.entity.iata.iata_orderretrieverq.IATAOrderRetrieveRQ;
import com.ktgj.common.spring.entity.iata.iata_orderretrieverq.OrderFilterCriteriaType;
import com.ktgj.common.spring.entity.iata.iata_orderviewrs.ResponseType;
import com.ktgj.common.spring.entity.iata.iata_orderviewrs.*;
import com.ktgj.common.spring.entity.interfaces.*;
import com.ktgj.flight.common.ruili.drdomain.BookingContactInfo;
import com.ktgj.flight.common.pay._Yeepay;
import com.ktgj.flight.domain.InterfaceEntity.*;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Service;

import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import java.math.BigDecimal;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 春秋机票接口
 */
@Service
public class _Spring {

    //春秋NDC测试环境地址
//    private final String s_JsonUrl = "http://101.230.218.71:8001/gdsgatewayota/";

    //http://192.168.191.12:7003/gdsgatewayota/  http://172.16.31.33:9529

    //测试环境 appKkey和 secret
//    private final String appkey = "ch1505807190957608960";
//    private final String secret = "01C4443A89784A3515292AB8A86DC022";


    //春秋NDC正式环境地址
//    private final String s_JsonUrl = "http://101.230.218.71:8001/gdsgatewayota/";

    //春秋NDC正式环境地址(JSON)
    private final String s_JsonUrl = "http://172.16.31.33:9529/gdsgatewayota/";
    //春秋NDC正式环境地址(Web Service)
    //private final String s_JsonUrl = "http://192.168.191.12:7002/soap/";

    //正式环境 appkey 和 secret
    private final String appkey = "ch1494562671665254400";
    private final String secret = "9F3411ADAED674343B89DFE6492DF177";


    //    加解密Key：JStZC7zKv3EHASw5
////    加解密类型：AES128
    private final String aesKey= "JStZC7zKv3EHASw5";

    /**
     * 春秋账号
     */
    private final String userName = "jstmc";

    /**
     * 春秋密码测试环境密码
     */
    private final String passWords = "0000";
    /**
     * 春秋密码正式环境密码
     */
    private final String passWord = "jstmc123";

//    /**
//     * 春秋测试url地址
//     */
//    private final String s_url = "http://101.230.218.71:8083/gds-ndc/soap/tmc?wsdl";
//
//    /**
//     * 春秋正式url地址
//     */
//    private final String s_urls = "http://172.16.31.33:9527/soap/tmc?wsdl";

    /**
     * 商旅通正式环境商户号
     */
    private String partner = "888880111110007";

    /**
     * 商旅通正式环境密钥
     */
    private String key = "090909090909090909";

    /**
     * 商旅通正式环境请求地址
     */
    private String payURL = "https://payment.ch.com/MacSuit/Pay?";

    /**
     * 商旅通测式环境商户号
     */
    private String partner1 = "666666";

    /**
     * 商旅通测式环境密钥
     */
    private String key1 = "666666";

    /**
     * 商旅通测式环境请求地址
     */
    private String payURL1 = "http://101.230.218.70:804/MacSuit/Pay";

    /**
     * 机票查询
     *
     * @param request
     * @return
     * @throws Exception
     */
    public MoFlightSearchResponse _FlightSearch(MoFlightSearchRequest request)  {
        MoFlightSearchResponse response = new MoFlightSearchResponse();

        if (StringUtils.isEmpty(request.GoSearchWhere.DepDate)) {
            response.ErrorMsg = "查询日期不能为空";
            response.ErrorCode = (EnumHelper.ReturnCode.请求参数为空).toString();
            return response;
        }

        if (StringUtils.isEmpty(request.GoSearchWhere.DstAirport)) {
            response.ErrorMsg = "到达地不能为空";
            response.ErrorCode = (EnumHelper.ReturnCode.请求参数为空).toString();
            return response;
        }

        if (StringUtils.isEmpty(request.GoSearchWhere.OrgAirport)) {
            response.ErrorMsg = "出发地不能为空";
            response.ErrorCode = (EnumHelper.ReturnCode.请求参数为空).toString();
            return response;
        }
        IATAAirShoppingRQ shoppingRQ = new IATAAirShoppingRQ();
        MessageDocType messageDocType = new MessageDocType();
        CountryType countryType = new CountryType();
        POSType posType = new POSType();
        RequestType requestType = new RequestType();
        FlightRequestType flightRequestType = new FlightRequestType();
        AffinityRequestType affinityRequestType = new AffinityRequestType();
        KeyValuePropertyType keyValuePropertyType = new KeyValuePropertyType();
        OriginDestCriteriaType originDestCriteriaType = new OriginDestCriteriaType();
        DestArrivalCriteriaType destArrivalCriteriaType = new DestArrivalCriteriaType();
        OriginDepCriteriaType originDepCriteriaType = new OriginDepCriteriaType();
        CurParameterType curParameterType = new CurParameterType();
        ResponseParametersType responseParametersType = new ResponseParametersType();

        messageDocType.setName("ndc");
        messageDocType.setRefVersionNumber(BigDecimal.valueOf(18.2));
        shoppingRQ.setMessageDoc(messageDocType);

        countryType.setCountryCode("CN");
        posType.setCountry(countryType);
        shoppingRQ.setPointOfSale(posType);

        keyValuePropertyType.setKeyText("FLTTYPE");
        //keyValuePropertyType.setValueText(String.valueOf(request.TripType));
        if (request.TripType == 1) {
            keyValuePropertyType.setValueText("N");
        } else if (request.TripType == 2) {
            keyValuePropertyType.setValueText("Y");
        }
        affinityRequestType.getKeywordPref().add(keyValuePropertyType);
        flightRequestType.setAffinityShoppingCriteria(affinityRequestType);

        destArrivalCriteriaType.setIATALocationCode(request.GoSearchWhere.DstAirport); //到达城市代码
        originDestCriteriaType.setDestArrivalCriteria(destArrivalCriteriaType);

        originDepCriteriaType.setDate(request.GoSearchWhere.DepDate); //出发日期
        originDepCriteriaType.setIATALocationCode(request.GoSearchWhere.OrgAirport); //出发城市代码
        originDestCriteriaType.setOriginDepCriteria(originDepCriteriaType);
        flightRequestType.getOriginDestCriteria().add(originDestCriteriaType);

        if (request.TripType == 2) {
            DestArrivalCriteriaType destArrivalCriteriaTypes = new DestArrivalCriteriaType();
            OriginDestCriteriaType originDestCriteriaTypes = new OriginDestCriteriaType();
            OriginDepCriteriaType originDepCriteriaTypes = new OriginDepCriteriaType();
            destArrivalCriteriaTypes.setIATALocationCode(request.BackSearchWhere.DstAirport); //到达城市代码
            originDestCriteriaTypes.setDestArrivalCriteria(destArrivalCriteriaTypes);

            originDepCriteriaTypes.setDate(request.BackSearchWhere.DepDate); //出发日期
            originDepCriteriaTypes.setIATALocationCode(request.BackSearchWhere.OrgAirport); //出发城市代码
            originDestCriteriaTypes.setOriginDepCriteria(originDepCriteriaTypes);
            flightRequestType.getOriginDestCriteria().add(originDestCriteriaTypes);
        }

        requestType.setFlightCriteria(flightRequestType);

        curParameterType.setName("CNY");
        responseParametersType.getCurParameter().add(curParameterType);
        requestType.setResponseParameters(responseParametersType);

        shoppingRQ.setRequest(requestType);

        AirShopping airShopping = new AirShopping();
        airShopping.setIATAAirShoppingRQ(shoppingRQ);

        try {
//            URL url;
//            url = new URL(s_urls);
//            QName qname = new QName("http://www.interfaces.gds.ch.com", "TmcWebServiceImplService");
//            TmcWebServiceImplService service = new TmcWebServiceImplService(url, qname);
//            TmcWebService tmcWebService = service.getTmcWebServiceImplPort();
//
//            BindingProvider bp = (BindingProvider) tmcWebService;
//            bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, userName);
//            bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, passWords);
//            bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, s_urls);
//            AirShoppingResponse airShoppingResponse = tmcWebService.airShopping(airShopping);
//            System.out.println(JSON.toJSONString(airShoppingResponse.getIATAAirShoppingRS().getResponse()));

            SpringTokenResponse tokenResponse = getToken();
            String urlInfo = this.s_JsonUrl + "apiFlightSearch/ota/FlightSearchService/airShopping";
            if (!tokenResponse.getIfSuccess().equals("Y"))
            {
                response.ErrorMsg = "获取Token失败";
                response.ErrorCode = (EnumHelper.ReturnCode.系统异常代码).toString();
            }
            HashMap<String,String> header = new HashMap<>();
            header.put("accessToken", tokenResponse.getOauth2ResultDTO().getAccessToken());
            String result = HttpClientUtil.doPostJsonWithHeaderMap(urlInfo, JSON.toJSONString(shoppingRQ), header);
            IATAAirShoppingRS iataAirShoppingRS = JSON.parseObject(result, IATAAirShoppingRS.class);
            if (iataAirShoppingRS.getResponse() == null || iataAirShoppingRS.getResponse().getOffersGroup().getCarrierOffers() == null || iataAirShoppingRS.getResponse().getOffersGroup().getCarrierOffers().size() == 0) {
                response.ErrorMsg = "第三方接口返回为null";
                response.ErrorCode = (EnumHelper.ReturnCode.接口返回参数为空).toString();
                return response;
            } else {
                List<CarrierOffersType> carrierOffers = iataAirShoppingRS.getResponse().getOffersGroup().getCarrierOffers();
                DataListsType dataListsType = iataAirShoppingRS.getResponse().getDataLists();
//                if (request.TripType == 1) {


                b:
                for (PaxSegmentType paxSegmentType : dataListsType.getPaxSegmentList().getPaxSegment()) {
                    MoFlightInfo moFlightInfo = new MoFlightInfo();

                    moFlightInfo.PaxSegmentRefID = paxSegmentType.getPaxSegmentID();//航段id
                    moFlightInfo.DepApt = paxSegmentType.getDep().getIATALocationCode();//出发机场代码
                    moFlightInfo.OrgAirport = paxSegmentType.getDep().getIATALocationCode();//出发机场三字码
                    if (paxSegmentType.getDep().getStationName() != null && !paxSegmentType.getDep().getStationName().equals("")) {
                        String stationName = paxSegmentType.getDep().getStationName();
                        String[] split = stationName.split("T");
                        if (split.length > 1)
                            moFlightInfo.DepTerm = "T" + split[1].charAt(0);//出发机场航站楼
                    }
                    moFlightInfo.OrgAirportName = paxSegmentType.getDep().getStationName().split("机场")[0] + "机场";
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");

//                    Object depFir = ReflectUtils.getFieldValue(paxSegmentType.getDep().getAircraftScheduledDateTime(), "firstChild");
//                    String depData = ReflectUtils.getFieldValue(depFir, "data");
                    String depData = paxSegmentType.getDep().getAircraftScheduledDateTime().toString();
                    Date depDate = dateFormat.parse(depData.split("T")[0] + " " + depData.split("T")[1].substring(0, 5));
                    moFlightInfo.DepDate = depDate;//出发时间
                    moFlightInfo.DepTime = depDate;//起飞时间

                    moFlightInfo.DstAirport = paxSegmentType.getArrival().getIATALocationCode();//抵达机场代码
                    moFlightInfo.ArrApt = paxSegmentType.getArrival().getIATALocationCode();//到达三字码
                    if (paxSegmentType.getArrival().getStationName() != null && !paxSegmentType.getArrival().getStationName().equals("")) {
                        String stationName = paxSegmentType.getArrival().getStationName();
                        String[] split = stationName.split("T");
                        if (split.length > 1)
                            moFlightInfo.ArrTerm = "T" + split[1].charAt(0);//到达机场航站楼
                    }
                    moFlightInfo.DstAirportName = paxSegmentType.getArrival().getStationName().split("机场")[0] + "机场";//抵达机场名称

//                    Object arrFir = ReflectUtils.getFieldValue(paxSegmentType.getArrival().getAircraftScheduledDateTime(), "firstChild");
//                    String arrData = ReflectUtils.getFieldValue(arrFir, "data");
                    String arrData = paxSegmentType.getArrival().getAircraftScheduledDateTime().toString();
                    Date arrDate = dateFormat.parse(arrData.split("T")[0] + " " + arrData.split("T")[1].substring(0, 5));
                    moFlightInfo.ArrDate = arrDate;//抵达时间
                    moFlightInfo.ArrTime = arrDate;//到达时间

                    moFlightInfo.Airline = "9C";
                    moFlightInfo.AirlineName = "春秋航空";
                    moFlightInfo.FlightNo = paxSegmentType.getOperatingCarrierInfo().getCarrierDesigCode() + paxSegmentType.getOperatingCarrierInfo().getOperatingCarrierFlightNumberText();//航班号
                    moFlightInfo.PlaneStyle = paxSegmentType.getDatedOperatingLeg().get(0).getCarrierAircraftType().getCarrierAircraftTypeCode();//机型

                    long diff = arrDate.getTime() - depDate.getTime();
                    long diffMinutes = diff / (60 * 1000) % 60;
                    long diffHours = diff / (60 * 60 * 1000) % 24;
                    long diffDays = diff / (24 * 60 * 60 * 1000);
                    StringBuffer stringBuffer = new StringBuffer();
                    if (diffDays > 0)
                        stringBuffer.append(diffDays + "天");
                    stringBuffer.append(diffHours + "小时");
                    stringBuffer.append(diffMinutes + "分");
                    moFlightInfo.flightTimes = stringBuffer.toString();//时长

                    if (request.TripType == 1) {
                        moFlightInfo.LegNum = 1;/**单程固定为1，往返需要判断*///1去程，2返程
                    } else if (request.TripType == 2) {
                        moFlightInfo.LegNum = 2;/**单程固定为1，往返需要判断*///1去程，2返程
                    }

                    a:
                    for (CarrierOffersType carrierOffersType : carrierOffers) {
                        if (carrierOffersType.getOffer().get(0).getOfferID().split("/")[1].split("_")[0].equals(paxSegmentType.getPaxSegmentID())) {
                            for (Offer1Type offer1Type : carrierOffersType.getOffer()) {
                                MoCabinInfo moCabinInfo = new MoCabinInfo();
                                if (offer1Type.getOfferQty().equals("9"))
                                    moCabinInfo.CabinLeftDesc = "座位充足";
                                else
                                    moCabinInfo.CabinLeftDesc = offer1Type.getOfferQty();
                                for (OfferItemType offerItemType : offer1Type.getOfferItem()) {
                                    MoCabinRule cabinRule = new MoCabinRule();
                                    FareDetailType fareDetailType = null;
                                    if (moFlightInfo.DepApt.equals(request.GoSearchWhere.OrgAirport) && moFlightInfo.ArrApt.equals(request.GoSearchWhere.DstAirport)) {
                                        fareDetailType = offerItemType.getFareDetail().get(0);
                                    } else if (moFlightInfo.DepApt.equals(request.BackSearchWhere.OrgAirport) && moFlightInfo.ArrApt.equals(request.BackSearchWhere.DstAirport)) {
                                        fareDetailType = offerItemType.getFareDetail().get(0);
                                    }
                                    FareRuleType fareRuleType = fareDetailType.getFareComponent().get(0).getFareRule().get(0);
                                    for (PenaltyType penaltyType : fareRuleType.getPenalty()) {
                                        Calendar calendar = new GregorianCalendar();
                                        dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                                        Map<String, Object> map = new HashMap<>();
                                        if (penaltyType.getTypeCode().value().equals("Other")) {
                                            if (penaltyType.getDescText() != null && penaltyType.getDescText().size() > 0) {
                                                /*String refund = penaltyType.getDescText().get(0);
                                                cabinRule.Refund = refund.substring(19);
                                                String change = penaltyType.getDescText().get(1);
                                                cabinRule.Change = change.substring(19);*/
                                                String baggage = penaltyType.getDescText().get(2);
                                                cabinRule.Baggage = baggage.substring(20);
                                            }
                                        }
                                        BigDecimal decimal = fareDetailType.getFareComponent().get(0).getPrice().getBaseAmount().getValue();
                                        if (penaltyType.getTypeCode().value().equals("Cancellation")) {
                                            if (penaltyType.getDescText().get(0).equals("1")) {
                                                map.put("time", dateFormat.format(depDate) + "后");
                                                for (PenaltyType type : fareRuleType.getPenalty()) {
                                                    if (type.getTypeCode().value().equals("Change")) {
                                                        if (type.getDescText().get(0).equals("1")) {
                                                            if (type.isChangeFeeInd()) {
                                                                BigDecimal multiply = decimal.multiply(type.getPenaltyPercent());
                                                                //BigDecimal subtract = fareDetailType.getFareComponent().get(0).getPrice().getBaseAmount().getValue().subtract(multiply);
                                                                map.put("changeRules", "￥ " + multiply + "/人");
                                                            } else {
                                                                map.put("changeRules", "不可变更");
                                                            }
                                                            break;
                                                        }
                                                    }
                                                }
                                            } else if (penaltyType.getDescText().get(0).equals("2")) {
                                                calendar.setTime(depDate);
                                                calendar.add(Calendar.HOUR_OF_DAY, -2);
                                                map.put("time", dateFormat.format(calendar.getTime()) + "--" + dateFormat.format(depDate));
                                                for (PenaltyType type : fareRuleType.getPenalty()) {
                                                    if (type.getTypeCode().value().equals("Change")) {
                                                        if (type.getDescText().get(0).equals("2")) {
                                                            if (type.isChangeFeeInd()) {
                                                                BigDecimal multiply = decimal.multiply(type.getPenaltyPercent());
                                                                //BigDecimal subtract = fareDetailType.getFareComponent().get(0).getPrice().getBaseAmount().getValue().subtract(multiply);
                                                                map.put("changeRules", "￥ " + multiply + "/人");
                                                            } else {
                                                                map.put("changeRules", "不可变更");
                                                            }
                                                            break;
                                                        }
                                                    }
                                                }
                                            } else if (penaltyType.getDescText().get(0).equals("3")) {
                                                calendar.setTime(depDate);
                                                calendar.add(Calendar.DATE, -1);
                                                Date time = calendar.getTime();
                                                calendar = new GregorianCalendar();
                                                calendar.setTime(depDate);
                                                calendar.add(Calendar.HOUR_OF_DAY, -2);
                                                map.put("time", dateFormat.format(time) + "--" + dateFormat.format(calendar.getTime()));
                                                for (PenaltyType type : fareRuleType.getPenalty()) {
                                                    if (type.getTypeCode().value().equals("Change")) {
                                                        if (type.getDescText().get(0).equals("3")) {
                                                            if (type.isChangeFeeInd()) {
                                                                BigDecimal multiply = decimal.multiply(type.getPenaltyPercent());
                                                                //BigDecimal subtract = fareDetailType.getFareComponent().get(0).getPrice().getBaseAmount().getValue().subtract(multiply);
                                                                map.put("changeRules", "￥ " + multiply + "/人");
                                                            } else {
                                                                map.put("changeRules", "不可变更");
                                                            }
                                                            break;
                                                        }
                                                    }
                                                }
                                            } else if (penaltyType.getDescText().get(0).equals("4")) {
                                                calendar.setTime(depDate);
                                                calendar.add(Calendar.DATE, -1);
                                                Date time = calendar.getTime();
                                                calendar.add(Calendar.DATE, -2);
                                                map.put("time", dateFormat.format(calendar.getTime()) + "--" + dateFormat.format(time));
                                                for (PenaltyType type : fareRuleType.getPenalty()) {
                                                    if (type.getTypeCode().value().equals("Change")) {
                                                        if (type.getDescText().get(0).equals("4")) {
                                                            if (type.isChangeFeeInd()) {
                                                                BigDecimal multiply = decimal.multiply(type.getPenaltyPercent());
                                                                //BigDecimal subtract = fareDetailType.getFareComponent().get(0).getPrice().getBaseAmount().getValue().subtract(multiply);
                                                                map.put("changeRules", "￥ " + multiply + "/人");
                                                            } else {
                                                                map.put("changeRules", "不可变更");
                                                            }
                                                            break;
                                                        }
                                                    }
                                                }
                                            } else if (penaltyType.getDescText().get(0).equals("5")) {
                                                calendar.setTime(depDate);
                                                calendar.add(Calendar.DATE, -3);
                                                Date time = calendar.getTime();
                                                calendar.add(Calendar.DATE, -4);
                                                map.put("time", dateFormat.format(calendar.getTime()) + "--" + dateFormat.format(time));
                                                for (PenaltyType type : fareRuleType.getPenalty()) {
                                                    if (type.getTypeCode().value().equals("Change")) {
                                                        if (type.getDescText().get(0).equals("5")) {
                                                            if (type.isChangeFeeInd()) {
                                                                BigDecimal multiply = decimal.multiply(type.getPenaltyPercent());
                                                                //BigDecimal subtract = fareDetailType.getFareComponent().get(0).getPrice().getBaseAmount().getValue().subtract(multiply);
                                                                map.put("changeRules", "￥ " + multiply + "/人");
                                                            } else {
                                                                map.put("changeRules", "不可变更");
                                                            }
                                                            break;
                                                        }
                                                    }
                                                }
                                            } else if (penaltyType.getDescText().get(0).equals("6")) {
                                                calendar.setTime(depDate);
                                                calendar.add(Calendar.DATE, -7);
                                                map.put("time", dateFormat.format(calendar.getTime()) + "前");
                                                for (PenaltyType type : fareRuleType.getPenalty()) {
                                                    if (type.getTypeCode().value().equals("Change")) {
                                                        if (type.getDescText().get(0).equals("6")) {
                                                            if (type.isChangeFeeInd()) {
                                                                BigDecimal multiply = decimal.multiply(type.getPenaltyPercent());
                                                                //BigDecimal subtract = fareDetailType.getFareComponent().get(0).getPrice().getBaseAmount().getValue().subtract(multiply);
                                                                map.put("changeRules", "￥ " + multiply + "/人");
                                                            } else {
                                                                map.put("changeRules", "不可变更");
                                                            }
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                            if (penaltyType.isCancelFeeInd()) {
                                                BigDecimal multiply = decimal.multiply(penaltyType.getPenaltyPercent());
                                                //BigDecimal subtract = fareDetailType.getFareComponent().get(0).getPrice().getBaseAmount().getValue().subtract(multiply);
                                                map.put("refundRules", "￥ " + multiply + "/人");
                                            } else {
                                                map.put("refundRules", "不可退票");
                                            }
                                            cabinRule.refundChangeRules.add(map);
                                        }
                                    }
                                    if (offerItemType.getOfferItemID().equals("ADT")) {
                                        moCabinInfo.CabinRule = cabinRule;
                                    } else if (offerItemType.getOfferItemID().equals("CHD")) {
                                        moCabinInfo.ChdCabinRule = cabinRule;
                                    } else if (offerItemType.getOfferItemID().equals("INF")) {
                                        if (cabinRule != null)
                                            moCabinInfo.IftCabinRule = cabinRule;
                                    }
                                }


                                OfferItemType ADTOfferItemType = null;
                                OfferItemType CHDOfferItemType = null;
                                OfferItemType INFOfferItemType = null;
                                for (OfferItemType offerItemType : offer1Type.getOfferItem()) {
                                    if (offerItemType.getOfferItemID().equals("ADT"))
                                        ADTOfferItemType = offerItemType;
                                    else if (offerItemType.getOfferItemID().equals("CHD"))
                                        CHDOfferItemType = offerItemType;
                                    else if (offerItemType.getOfferItemID().equals("INF"))
                                        INFOfferItemType = offerItemType;
                                }
                                if (request.hasChildren && CHDOfferItemType == null)
                                    continue b;

                                if (request.hasChildren)
                                {
                                    //moCabinInfo.CallCenterAmountInfo.TicketAmount = ADTOfferItemType.getPrice().getTotalAmount().getValue();//从SHOPPING获取的基价(携带一名儿童）
                                    if (moFlightInfo.DepApt.equals(request.GoSearchWhere.OrgAirport) && moFlightInfo.ArrApt.equals(request.GoSearchWhere.DstAirport)) {
                                        moCabinInfo.CallCenterAmountInfo.OrgTicketAmount = ADTOfferItemType.getFareDetail().get(0).getFareComponent().get(0).getPrice().getBaseAmount().getValue();//从SHOPPING获取的基价(携带一名儿童）
                                        if (CHDOfferItemType != null)
                                            moCabinInfo.CallCenterAmountInfo.OrgChdTicketAmount = CHDOfferItemType.getFareDetail().get(0).getFareComponent().get(0).getPrice().getBaseAmount().getValue();//从SHOPPING获取的基价(携带一名儿童）
                                        if (INFOfferItemType != null)
                                            moCabinInfo.CallCenterAmountInfo.OrgIftTicketAmount = INFOfferItemType.getFareDetail().get(0).getFareComponent().get(0).getPrice().getBaseAmount().getValue();//从SHOPPING获取的基价(携带一名婴儿）
                                    } else if (moFlightInfo.DepApt.equals(request.BackSearchWhere.OrgAirport) && moFlightInfo.ArrApt.equals(request.BackSearchWhere.DstAirport)) {
                                        moCabinInfo.CallCenterAmountInfo.OrgTicketAmount = ADTOfferItemType.getFareDetail().get(0).getFareComponent().get(0).getPrice().getBaseAmount().getValue();//从SHOPPING获取的基价(携带一名儿童）
                                        if (CHDOfferItemType != null)
                                            moCabinInfo.CallCenterAmountInfo.OrgChdTicketAmount = CHDOfferItemType.getFareDetail().get(0).getFareComponent().get(0).getPrice().getBaseAmount().getValue();//从SHOPPING获取的基价(携带一名儿童）
                                        if (INFOfferItemType != null)
                                            moCabinInfo.CallCenterAmountInfo.OrgIftTicketAmount = INFOfferItemType.getFareDetail().get(0).getFareComponent().get(0).getPrice().getBaseAmount().getValue();//从SHOPPING获取的基价(携带一名婴儿）
                                    }
                                }
                                else
                                {
                                    //moCabinInfo.CallCenterAmountInfo.TicketAmount = ADTOfferItemType.getPrice().getTotalAmount().getValue();//从SHOPPING获取的基价
                                    if (moFlightInfo.DepApt.equals(request.GoSearchWhere.OrgAirport) && moFlightInfo.ArrApt.equals(request.GoSearchWhere.DstAirport)) {
                                        moCabinInfo.CallCenterAmountInfo.OrgTicketAmount = ADTOfferItemType.getFareDetail().get(0).getFareComponent().get(0).getPrice().getBaseAmount().getValue();//从SHOPPING获取的基价(携带一名儿童）
                                    } else if (moFlightInfo.DepApt.equals(request.BackSearchWhere.OrgAirport) && moFlightInfo.ArrApt.equals(request.BackSearchWhere.DstAirport)) {
                                        moCabinInfo.CallCenterAmountInfo.OrgTicketAmount = ADTOfferItemType.getFareDetail().get(0).getFareComponent().get(0).getPrice().getBaseAmount().getValue();//从SHOPPING获取的基价(携带一名儿童）
                                    }
                                }

                                moCabinInfo.CallCenterAmountInfo.TicketAmount = new BigDecimal(paxSegmentType.getOperatingCarrierInfo().getDisclosure().getDesc().get(0).getDescText());
                                /*if (moCabinInfo.CallCenterAmountInfo.OrgTicketAmount != null && moCabinInfo.CallCenterAmountInfo.TicketAmount != null) {
                                    BigDecimal multiply = null;
                                    BigDecimal divide = moCabinInfo.CallCenterAmountInfo.OrgTicketAmount.divide(moCabinInfo.CallCenterAmountInfo.TicketAmount, 2, BigDecimal.ROUND_HALF_UP);
                                    if (divide.compareTo(new BigDecimal(1)) > 0)
                                        multiply = new BigDecimal(1).multiply(new BigDecimal(100));
                                    else
                                        multiply = divide.multiply(new BigDecimal(100));
                                    moCabinInfo.CallCenterAmountInfo.DisCountRate = multiply;
                                }*/

//                                if (moFlightInfo.Price == null) {
//                                    moFlightInfo.Price = moCabinInfo.BaseAmount;
//                                    moFlightInfo.TicketAmount = moCabinInfo.BaseAmount;
//                                } else if (moFlightInfo.Price.compareTo(moCabinInfo.BaseAmount) == 1) {
//                                    moFlightInfo.Price = moCabinInfo.BaseAmount;
//                                    moFlightInfo.TicketAmount = moCabinInfo.BaseAmount;
//                                }

                                if (ADTOfferItemType != null) {
                                    FareDetailType ADTFareDetailType = ADTOfferItemType.getFareDetail().get(0);/**单程返回list大小为1，往返返回list大小为2*/
                                    FareComponentType ADTFareComponentType = ADTFareDetailType.getFareComponent().get(0);/**list大小固定为1*/
                                    FareDetailType chdFareDetailType = null;
                                    FareComponentType chdFareComponentType = null;
                                    if (CHDOfferItemType != null) {
                                        chdFareDetailType = CHDOfferItemType.getFareDetail().get(0);/**单程返回list大小为1，往返返回list大小为2*/
                                        chdFareComponentType = chdFareDetailType.getFareComponent().get(0);/**list大小固定为1*/
                                    }
                                    moCabinInfo.Cabin = ADTFareComponentType.getRBD().getRBDCode().getName();//舱位
                                    moCabinInfo.CabinMark = offer1Type.getOfferID();//舱位标识  类型（"Y"-往返航班，"N"-单程航班）/航段ID_舱位_舱位价格_套餐类型_组合产品编号_当前x产品的id_当前x产品购买份数_当前x产品的附加信息
                                    if (ADTFareComponentType.getCabinType().getCabinTypeName().equals("S")) {
                                        moCabinInfo.BaseCabin = "C";//舱位等级
                                        moCabinInfo.BaseCabinName = "商务舱";
                                    }
                                    if (ADTFareComponentType.getCabinType().getCabinTypeName().equals("C")) {
                                        moCabinInfo.BaseCabin = "Y";//舱位等级
                                        moCabinInfo.BaseCabinName = "经济舱";
                                    }
                                    if (ADTFareComponentType.getCabinType().getCabinTypeName().equals("N")) {
                                        moCabinInfo.BaseCabin = "Y";//舱位等级
                                        moCabinInfo.BaseCabinName = "普通舱";
                                    }

                                    if (moFlightInfo.FuelTax == null && moFlightInfo.AirportTax == null && moFlightInfo.ChildFuelTax == null && moFlightInfo.ChildAirportTax == null) {
                                        for (TaxType taxType : ADTFareComponentType.getPrice().getTaxSummary().get(0).getTax()) {
                                            switch (taxType.getTaxCode()) {
                                                case "YQ":
                                                    moFlightInfo.FuelTax = taxType.getAmount().getValue();//燃油费
                                                    break;
                                                case "CN":
                                                    moFlightInfo.AirportTax = taxType.getAmount().getValue();//机场建设费
                                            }
                                        }
                                        if (chdFareDetailType != null && chdFareComponentType != null) {//如果有儿童票的话
                                            for (TaxType taxType : chdFareComponentType.getPrice().getTaxSummary().get(0).getTax()) {
                                                switch (taxType.getTaxCode()) {
                                                    case "YQ":
                                                        moFlightInfo.ChildFuelTax = taxType.getAmount().getValue();//儿童燃油费
                                                        break;
                                                    case "CN":
                                                        moFlightInfo.ChildAirportTax = taxType.getAmount().getValue();//儿童机场建设费
                                                }
                                            }
                                        }
                                    }

                                }
                                moFlightInfo.ListCabinInfo.add(moCabinInfo);
                            }
                            break a;
                        }
                    }

                    if (moFlightInfo.DepApt.equals(request.GoSearchWhere.OrgAirport) && moFlightInfo.ArrApt.equals(request.GoSearchWhere.DstAirport))
                        response.ListGoFlightInfo.add(moFlightInfo);
                    else if (moFlightInfo.DepApt.equals(request.BackSearchWhere.OrgAirport) && moFlightInfo.ArrApt.equals(request.BackSearchWhere.DstAirport))
                        response.ListBackFlightInfo.add(moFlightInfo);
                }


//                } else if (request.TripType == 2) {
//                    for (CarrierOffersType carrierOffer : carrierOffers) {
//                        for (Offer1Type offer1Type : carrierOffer.getOffer()) {
//                            for (OfferItemType itemType : offer1Type.getOfferItem()) {
//                                for (FareDetailType fareDetailType : itemType.getFareDetail()) {
//                                    for (FareComponentType fareComponentType : fareDetailType.getFareComponent()) {
//                                        TripCroup tcp = new TripCroup();
//                                        Trip tpGo = new Trip();
//                                        String paxJourneyRefID = offer1Type.getJourneyOverview().getJourneyPriceClass().get(0).getPaxJourneyRefID();//航段信息 flightNo_航段
//                                        String[] arr = paxJourneyRefID.split("_");
//                                        tpGo.FlightNo = arr[0];
//                                        tpGo.DstAirport = arr[1].substring(0, 3);
//                                        tpGo.OrgAirport = arr[1].substring(3, 6);
//                                        tpGo.CabinMark = fareComponentType.getCabinType().getCabinTypeName(); //舱位标识
//                                        tpGo.Cabin = fareComponentType.getRBD().getRBDCode().getName(); //舱位名称
//                                        tpGo.Price = fareComponentType.getPrice().getBaseAmount().getValue(); //舱位价格
//                                        tcp.ListTrip.add(tpGo);
//                                        response.TripCroupList.add(tcp);
//                                    }
//                                }
//                            }
//                        }
//                    }
//                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return response;
    }

    /**
     * 预下单 非会员
     *
     * @param request
     * @return
     */
    public MoCreateOrderResponse _OrderCreateNormal(MoCreateOrderRequest request) {
        MoCreateOrderResponse response = new MoCreateOrderResponse();
        com.ktgj.common.spring.entity.iata.iata_ordercreaterq.MessageDocType messageDocType = new com.ktgj.common.spring.entity.iata.iata_ordercreaterq.MessageDocType();
        com.ktgj.common.spring.entity.iata.iata_ordercreaterq.CountryType countryType = new com.ktgj.common.spring.entity.iata.iata_ordercreaterq.CountryType();
        com.ktgj.common.spring.entity.iata.iata_ordercreaterq.DeviceType deviceType = new com.ktgj.common.spring.entity.iata.iata_ordercreaterq.DeviceType();
        com.ktgj.common.spring.entity.iata.iata_ordercreaterq.POSType posType = new com.ktgj.common.spring.entity.iata.iata_ordercreaterq.POSType();
        com.ktgj.common.spring.entity.iata.iata_ordercreaterq.RequestType requestType = new com.ktgj.common.spring.entity.iata.iata_ordercreaterq.RequestType();
        CreateOrderType createOrderType = new CreateOrderType();
        SelectedOfferType selectedOfferType = new SelectedOfferType();
        SelectedOfferItemType selectedOfferItemType = new SelectedOfferItemType();
        com.ktgj.common.spring.entity.iata.iata_ordercreaterq.PaxGroupType paxGroupType = new com.ktgj.common.spring.entity.iata.iata_ordercreaterq.PaxGroupType();
        com.ktgj.common.spring.entity.iata.iata_ordercreaterq.DataListsType dataListsType = new com.ktgj.common.spring.entity.iata.iata_ordercreaterq.DataListsType();
        com.ktgj.common.spring.entity.iata.iata_ordercreaterq.ContactInfoListType contactInfoListType = new com.ktgj.common.spring.entity.iata.iata_ordercreaterq.ContactInfoListType();
        com.ktgj.common.spring.entity.iata.iata_ordercreaterq.ContactInfoType contactInfoType = new com.ktgj.common.spring.entity.iata.iata_ordercreaterq.ContactInfoType();
        com.ktgj.common.spring.entity.iata.iata_ordercreaterq.EmailAddressType emailAddressType = new com.ktgj.common.spring.entity.iata.iata_ordercreaterq.EmailAddressType();
        com.ktgj.common.spring.entity.iata.iata_ordercreaterq.PhoneType phoneType = new com.ktgj.common.spring.entity.iata.iata_ordercreaterq.PhoneType();
        com.ktgj.common.spring.entity.iata.iata_ordercreaterq.PostalAddressType postalAddressType = new com.ktgj.common.spring.entity.iata.iata_ordercreaterq.PostalAddressType();
        com.ktgj.common.spring.entity.iata.iata_ordercreaterq.IndividualType individualType = new com.ktgj.common.spring.entity.iata.iata_ordercreaterq.IndividualType();
        com.ktgj.common.spring.entity.iata.iata_ordercreaterq.PaxListType paxListType = new com.ktgj.common.spring.entity.iata.iata_ordercreaterq.PaxListType();
        com.ktgj.common.spring.entity.iata.iata_ordercreaterq.PaxType paxType = new com.ktgj.common.spring.entity.iata.iata_ordercreaterq.PaxType();
        com.ktgj.common.spring.entity.iata.iata_ordercreaterq.MeasureType measureType = new com.ktgj.common.spring.entity.iata.iata_ordercreaterq.MeasureType();
        com.ktgj.common.spring.entity.iata.iata_ordercreaterq.IdentityDocType identityDocType = new com.ktgj.common.spring.entity.iata.iata_ordercreaterq.IdentityDocType();
        IATAOrderCreateRQ orderCreateRQ = new IATAOrderCreateRQ();

        messageDocType.setName("ndc");
        messageDocType.setRefVersionNumber(BigDecimal.valueOf(18.2));
        orderCreateRQ.setMessageDoc(messageDocType);

        countryType.setCountryCode("CN");
        countryType.setCountryName("China");
        posType.setCountry(countryType);

        deviceType.setIPAddressText("127.0.0.1"); //客户端IP
        posType.setDevice(deviceType);
        orderCreateRQ.setPointOfSale(posType);

        selectedOfferType.setOfferRefID(request.OfferRefID);
        selectedOfferType.setOwnerCode("9C");

        com.ktgj.common.spring.entity.iata.iata_ordercreaterq.IndividualType individualType1 = new com.ktgj.common.spring.entity.iata.iata_ordercreaterq.IndividualType();
        int pax = 0;
        for (MoPassenger moPassenger : request.ListMoPassenger) {
            if (moPassenger.Sex)
                individualType1.setGenderCode(com.ktgj.common.spring.entity.iata.iata_ordercreaterq.GenderCodeContentType.M);
            else
                individualType1.setGenderCode(com.ktgj.common.spring.entity.iata.iata_ordercreaterq.GenderCodeContentType.F);
            individualType1.setSurname(moPassenger.PassengerName);
            paxType.setIndividual(individualType1);
            if (moPassenger.PassengerType == 1) {
                paxType.setPTC("ADT");
                selectedOfferItemType.setOfferItemRefID("ADT");
            } else if (moPassenger.PassengerType == 2) {
                paxType.setPTC("CHD");
                selectedOfferItemType.setOfferItemRefID("CHD");
            } else if (moPassenger.PassengerType == 3) {
                paxType.setPTC("INF");
                selectedOfferItemType.setOfferItemRefID("INF");
            }
            pax += 1;
            paxType.setPaxID("P_" + pax);
            selectedOfferItemType.getPaxRefID().add(paxType.getPaxID());
            measureType.setValue(BigDecimal.valueOf(moPassenger.age));
            paxType.setAgeMeasure(measureType);
            identityDocType.setIdentityDocID(moPassenger.IDNO); //乘客证件号
            switch (String.valueOf(moPassenger.IDType)) {
                case "1":
                    identityDocType.setIdentityDocTypeCode("1");
                    break;
                case "2":
                    identityDocType.setIdentityDocTypeCode("9");
                    break;
                case "4":
                    identityDocType.setIdentityDocTypeCode("2");
                    break;
                case "5":
                    identityDocType.setIdentityDocTypeCode("10");
                    break;
                case "7":
                    identityDocType.setIdentityDocTypeCode("3");
                    break;
                case "9":
                    identityDocType.setIdentityDocTypeCode("13");
                    break;
                case "10":
                    identityDocType.setIdentityDocTypeCode("5");
                    break;
            }

            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String format = dateFormat.format(moPassenger.Birthday);
            paxType.setBirthdate(format); //乘客生日
            identityDocType.setExpiryDate(moPassenger.IDValidDate); //证件到期日
            paxType.setCitizenshipCountryCode("CHN"); //国籍三字码
            paxType.setContactInfoRefID("CI_" + pax);
            paxType.getIdentityDoc().add(identityDocType);
            paxListType.getPax().add(paxType);
        }
        selectedOfferType.getSelectedOfferItem().add(selectedOfferItemType);
        createOrderType.getSelectedOffer().add(selectedOfferType);
        requestType.setCreateOrder(createOrderType);

        //下单人
        paxGroupType.getContactInfoRefID().add("CI_1");
        requestType.getPaxGroup().add(paxGroupType);

        contactInfoType.setContactInfoID("CI_1");

        emailAddressType.setEmailAddressText(BookingContactInfo.Email); //下单人电子邮件
        contactInfoType.getEmailAddress().add(emailAddressType);

        phoneType.setPhoneNumber(new BigDecimal(BookingContactInfo.MobilePhone)); //下单人手机号
        contactInfoType.getPhone().add(phoneType);

        postalAddressType.setBuildingRoomText(BookingContactInfo.Address); //下单人地址
        /*postalAddressType.setPostalCode("200000");*/
        contactInfoType.getPostalAddress().add(postalAddressType);

        //下单人姓名
        individualType.setSurname(BookingContactInfo.ContactName); //下单人姓名
        contactInfoType.setIndividual(individualType);

        contactInfoListType.getContactInfo().add(contactInfoType);
        dataListsType.setContactInfoList(contactInfoListType);

        dataListsType.setPaxList(paxListType);
        requestType.setDataLists(dataListsType);
        orderCreateRQ.setRequest(requestType);

        OrderCreate orderCreate1 = new OrderCreate();
        orderCreate1.setIATAOrderCreateRQ(orderCreateRQ);

        try {
//            URL url;
//            url = new URL(s_JsonUrl);
//            QName qname = new QName("http://www.interfaces.gds.ch.com", "TmcWebServiceImplService");
//            TmcWebServiceImplService service = new TmcWebServiceImplService(url, qname);
//            TmcWebService tmcWebService = service.getTmcWebServiceImplPort();
//
//            BindingProvider bp = (BindingProvider) tmcWebService;
//            bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, userName);
//            bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, passWord);
//            bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, s_JsonUrl);
//            OrderCreateResponse orderCreateResponse = tmcWebService.orderCreate(orderCreate1);
//            System.out.println(orderCreateResponse.getIATAOrderViewRS().getResponse().getOrder().get(0));

            SpringTokenResponse tokenResponse = getToken();
            String urlInfo = this.s_JsonUrl + "apiOrder/ota/orderOtaCtr/orderCreate";
            if (!tokenResponse.getIfSuccess().equals("Y"))
            {
                response.ErrorMsg = "获取Token失败";
                response.ErrorCode = (EnumHelper.ReturnCode.系统异常代码).toString();
                response.IsSuccess = false;
            }
            HashMap<String,String> header = new HashMap<>();
            header.put("accessToken", tokenResponse.getOauth2ResultDTO().getAccessToken());
            String result = HttpClientUtil.doPostJsonWithHeaderMap(urlInfo, JSON.toJSONString(orderCreateRQ), header);
            IATAOrderViewRS orderViewRS = JSON.parseObject(result, IATAOrderViewRS.class);

            if (orderViewRS.getError() != null && orderViewRS.getError().size() > 0) {
                if (orderViewRS.getError().get(0).getError().get(0).getCode() != null && !orderViewRS.getError().get(0).getError().get(0).getCode().equals("") &&
                        orderViewRS.getError().get(0).getError().get(0).getDescText() != null && !orderViewRS.getError().get(0).getError().get(0).getDescText().equals("")) {
                    response.ErrorCode = orderViewRS.getError().get(0).getError().get(0).getCode();
                    response.ErrorMsg = orderViewRS.getError().get(0).getError().get(0).getDescText();
                    response.IsSuccess = false;
                    return response;
                }
                if (orderViewRS.getError().get(0).getError().get(0).getStatusText().equals("Y"))
                    response.IsSuccess = true;
                else
                    response.IsSuccess = false;
            }

            response.MainOrderID = orderViewRS.getResponse().getOrder().get(0).getOrderID();
            response.PayAmount = orderViewRS.getResponse().getOrder().get(0).getTotalPrice().getTotalAmount().getValue();

            /*IATAOrderViewRS orderViewRS = new IATAOrderViewRS();
            ErrorsType errorsTypes = null;
            MoOrderDetail moOrderDetail = null;
            MoResponse moResponse = new MoResponse();
            for (ErrorsType errorsType : orderCreateResponse.getIATAOrderViewRS().getError()) {
                errorsTypes = errorsType;
                ErrorType errorTypes = new ErrorType();
                for (ErrorType errorType : errorsType.getError()) {
                    errorTypes.setDescText(errorType.getDescText());
                    errorTypes.setStatusText(errorType.getStatusText());
                    moResponse.ErrorMsg = errorType.getStatusText();
                    response.ErrorMsg = moResponse.ErrorMsg;
                }
                errorsType.getError().add(errorTypes);
            }
            orderViewRS.getError().add(errorsTypes);

            com.ktgj.common.spring.entity.iata.iata_orderviewrs.OrderType orderTypes = new com.ktgj.common.spring.entity.iata.iata_orderviewrs.OrderType();
            for (com.ktgj.common.spring.entity.iata.iata_orderviewrs.OrderType orderType : orderCreateResponse.getIATAOrderViewRS().getResponse().getOrder()) {
                moOrderDetail = new MoOrderDetail();
                orderTypes.setOrderID(orderType.getOrderID());
                moOrderDetail.OrderID = orderType.getOrderID();

                com.ktgj.common.spring.entity.iata.iata_orderviewrs.PriceType priceType = new com.ktgj.common.spring.entity.iata.iata_orderviewrs.PriceType();
                com.ktgj.common.spring.entity.interfaces.AmountType amountType = new com.ktgj.common.spring.entity.interfaces.AmountType();
                amountType.setValue(orderType.getTotalPrice().getTotalAmount().getValue());
                amountType.setCurCode(orderType.getTotalPrice().getTotalAmount().getCurCode());
                priceType.setTotalAmount(amountType);
                orderTypes.setTotalPrice(priceType);
                moOrderDetail.OrderAmount = orderType.getTotalPrice().getTotalAmount().getValue();
                response.ListMoOrderDetail.add(moOrderDetail);
            }
            com.ktgj.common.spring.entity.iata.iata_orderviewrs.ResponseType responseType = new com.ktgj.common.spring.entity.iata.iata_orderviewrs.ResponseType();
            if (orderTypes != null) {
                responseType.getOrder().add(orderTypes);
            }
            orderViewRS.setResponse(responseType);*/
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        }
        return response;
    }

    /**
     * 订单查询
     *
     * @param request
     * @return
     */
    public MoQueryOrderResponse _QueryOrderInfo(MoQueryOrderRequest request) {
        MoQueryOrderResponse response = new MoQueryOrderResponse();
        IATAOrderRetrieveRQ orderRetrieveRQ = new IATAOrderRetrieveRQ();
        com.ktgj.common.spring.entity.iata.iata_orderretrieverq.OrderType orderType = new com.ktgj.common.spring.entity.iata.iata_orderretrieverq.OrderType();
        OrderFilterCriteriaType orderFilterCriteriaType = new OrderFilterCriteriaType();
        com.ktgj.common.spring.entity.iata.iata_orderretrieverq.RequestType requestType = new com.ktgj.common.spring.entity.iata.iata_orderretrieverq.RequestType();

        orderType.setOrderID(request.OrderID); //订单号
        orderFilterCriteriaType.setOrder(orderType);
        requestType.setOrderFilterCriteria(orderFilterCriteriaType);
        orderRetrieveRQ.setRequest(requestType);

        OrderRetrieve orderRetrieve = new OrderRetrieve();
        orderRetrieve.setIATAOrderRetrieveRQ(orderRetrieveRQ);

        //URL url;
        try {
            /*url = new URL(s_JsonUrl);
            QName qname = new QName("http://www.interfaces.gds.ch.com", "TmcWebServiceImplService");
            TmcWebServiceImplService service = new TmcWebServiceImplService(url, qname);
            TmcWebService tmcWebService = service.getTmcWebServiceImplPort();

            BindingProvider bp = (BindingProvider) tmcWebService;
            bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, userName);
            bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, passWord);
            bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, s_JsonUrl);
            OrderRetrieveResponse orderRetrieveResponse = tmcWebService.orderRetrieve(orderRetrieve);*/

            SpringTokenResponse tokenResponse = getToken();
            String urlInfo = this.s_JsonUrl + "apiOrder/ota/orderOtaCtr/orderRetrieve";
            if (!tokenResponse.getIfSuccess().equals("Y"))
            {
                response.ErrorMsg = "获取Token失败";
                response.ErrorCode = (EnumHelper.ReturnCode.系统异常代码).toString();
                response.IsSuccess = false;
            }
            HashMap<String,String> header = new HashMap<>();
            header.put("accessToken", tokenResponse.getOauth2ResultDTO().getAccessToken());
            String result = HttpClientUtil.doPostJsonWithHeaderMap(urlInfo, JSON.toJSONString(orderRetrieveRQ), header);
            IATAOrderViewRS orderViewRS = JSON.parseObject(result, IATAOrderViewRS.class);

            if (orderViewRS.getError() != null && orderViewRS.getError().size() > 0) {
                if (orderViewRS.getError().get(0).getError().get(0).getCode() != null && !orderViewRS.getError().get(0).getError().get(0).getCode().equals("") &&
                        orderViewRS.getError().get(0).getError().get(0).getDescText() != null && !orderViewRS.getError().get(0).getError().get(0).getDescText().equals("")) {
                    response.ErrorCode = orderViewRS.getError().get(0).getError().get(0).getCode();
                    response.ErrorMsg = orderViewRS.getError().get(0).getError().get(0).getDescText();
                    response.IsSuccess = false;
                    return response;
                }
            }

            response.OrderID = orderViewRS.getResponse().getOrder().get(0).getOrderID();
            MoPayInfo payInfo = new MoPayInfo();
            payInfo.PayStatusMsg = orderViewRS.getResponse().getOrder().get(0).getStatusCode().value();
            response.ListPayInfo.add(payInfo);
            response.Amount = orderViewRS.getResponse().getOrder().get(0).getTotalPrice().getTotalAmount().getValue();
            //response.Contacts.ContactEmail = orderViewRS.getResponse().getDataLists().getContactInfoList().getContactInfo().get(0).getEmailAddress().get(0).getEmailAddressText();
            response.Contacts.ContactMobile = orderViewRS.getResponse().getDataLists().getContactInfoList().getContactInfo().get(0).getPhone().get(0).getPhoneNumber().toString();
            //response.Contacts.Address = orderViewRS.getResponse().getDataLists().getContactInfoList().getContactInfo().get(0).getPostalAddress().get(0).getBuildingRoomText();

            for (int i = 0; i < orderViewRS.getResponse().getOrder().get(0).getOrderItem().size(); i++) {
                MoPassenger passenger = new MoPassenger();
                passenger.TicketAmount = orderViewRS.getResponse().getOrder().get(0).getOrderItem().get(i).getPrice().getBaseAmount().getValue();
                orderViewRS.getResponse().getOrder().get(0).getOrderItem().get(i).getPrice().getTaxSummary().get(0).getTax().forEach(items -> {
                    switch (items.getTaxCode()) {
                        case "YQ":
                            passenger.FuelTax = items.getAmount().getValue();
                            break;
                        case "CN":
                            passenger.AirportTax = items.getAmount().getValue();
                            break;
                    }
                });
                passenger.PassengerName = orderViewRS.getResponse().getDataLists().getPaxList().getPax().get(i).getIndividual().getSurname();
                switch (orderViewRS.getResponse().getDataLists().getPaxList().getPax().get(i).getIndividual().getGenderCode().value()) {
                    case "M":
                        passenger.Sex = true;
                        break;
                    case "F":
                        passenger.Sex = false;
                        break;
                }

                /**
                 * 1	身份证（国内）	10	回乡证（国内|区域）
                 * 2	护照（国内|区域|国际）	11	旅行证（国内）
                 * 3	台胞证（国内|区域）	12	外侨证（国内）
                 * 4	军官证（国内）	13	港澳通行证（国内|区域）
                 * 5	户口薄（国内）	14	空服员证件（国内）
                 * 6	警官证（国内）	17  台湾通行证（国内）
                 * 19  台湾通行证（区域|国际）
                 * 7	离退休干部证（国内）	18	海员证
                 * 8	部队离退休证（国内）	20	外国人永久居留身份证
                 * 9	士兵证（国内）	        21	港澳台居民居住证
                 */
                passenger.IDType = Integer.parseInt(orderViewRS.getResponse().getDataLists().getPaxList().getPax().get(i).getIdentityDoc().get(0).getIdentityDocTypeCode());
                passenger.IDNO = orderViewRS.getResponse().getDataLists().getPaxList().getPax().get(i).getIdentityDoc().get(0).getIdentityDocID();
                passenger.IDValidDate = (Date) orderViewRS.getResponse().getDataLists().getPaxList().getPax().get(i).getIdentityDoc().get(0).getExpiryDate();
                switch (orderViewRS.getResponse().getDataLists().getPaxList().getPax().get(i).getPTC()) {
                    case "ADT":
                        passenger.PassengerType = 1;
                        break;
                    case "CHD":
                        passenger.PassengerType = 2;
                        break;
                    case "INF":
                        passenger.PassengerType = 3;
                        break;
                }
                switch (orderViewRS.getResponse().getOrder().get(0).getOrderItem().get(i).getStatusCode().value()) {
                    case "DESTINE":
                        passenger.Status = EnumHelper.OrderStatus.下单成功等待支付.getValue();
                        break;
                    case "TICKETING":
                        passenger.Status = EnumHelper.OrderStatus.出票完成.getValue();
                        break;
                    case "SOLDTICKET":
                        passenger.Status = EnumHelper.OrderStatus.支付成功等待出票.getValue();
                        break;
                    case "TIMEOUTCANCEL":
                        passenger.Status = EnumHelper.OrderStatus.订单取消.getValue();
                        break;
                    case "INITIATIVECANCEL":
                        passenger.Status = EnumHelper.OrderStatus.订单取消.getValue();
                        break;
                    case "APPLYREFUND":
                        passenger.Status = EnumHelper.OrderStatus.退票申请.getValue();
                        break;
                    case "FLIGHTCHANGECANCEL":
                        passenger.Status = EnumHelper.OrderStatus.订单取消.getValue();
                        break;
                    case "TAKEFLIGHT":
                        passenger.Status = EnumHelper.OrderStatus.已使用.getValue();
                        break;
                    case "REFUNDED":
                        passenger.Status = EnumHelper.OrderStatus.退票完成.getValue();
                        break;
                }
                response.ListMoPassenger.add(passenger);
            }

            MoSegment segment = new MoSegment();
            segment.PlaneStyle = orderViewRS.getResponse().getDataLists().getPaxSegmentList().getPaxSegment().get(0).getDatedOperatingLeg().get(0).getCarrierAircraftType().getCarrierAircraftTypeCode();
            segment.Airline = orderViewRS.getResponse().getDataLists().getPaxSegmentList().getPaxSegment().get(0).getOperatingCarrierInfo().getCarrierDesigCode();
            segment.FlightNo = orderViewRS.getResponse().getDataLists().getPaxSegmentList().getPaxSegment().get(0).getOperatingCarrierInfo().getOperatingCarrierFlightNumberText();
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String depDateTime = orderViewRS.getResponse().getDataLists().getPaxSegmentList().getPaxSegment().get(0).getDep().getAircraftScheduledDateTime().toString();
            String substring = depDateTime.substring(0, depDateTime.length() - 10);
            String[] ts = substring.split("T");
            segment.DepDate = format.parse(ts[0] + " " + ts[1]);
            segment.OrgAirport = orderViewRS.getResponse().getDataLists().getPaxSegmentList().getPaxSegment().get(0).getDep().getIATALocationCode();
            segment.DstAirport = orderViewRS.getResponse().getDataLists().getPaxSegmentList().getPaxSegment().get(0).getArrival().getIATALocationCode();
            response.ListBackSegment.add(segment);
            if (orderViewRS.getResponse().getDataLists().getPaxSegmentList().getPaxSegment().size() > 1) {
                segment = new MoSegment();
                segment.PlaneStyle = orderViewRS.getResponse().getDataLists().getPaxSegmentList().getPaxSegment().get(1).getDatedOperatingLeg().get(0).getCarrierAircraftType().getCarrierAircraftTypeCode();
                segment.Airline = orderViewRS.getResponse().getDataLists().getPaxSegmentList().getPaxSegment().get(1).getMarketingCarrierInfo().getCarrierDesigCode();
                segment.FlightNo = orderViewRS.getResponse().getDataLists().getPaxSegmentList().getPaxSegment().get(1).getMarketingCarrierInfo().getMarketingCarrierFlightNumberText();
                String backDateTime = orderViewRS.getResponse().getDataLists().getPaxSegmentList().getPaxSegment().get(1).getDep().getAircraftScheduledDateTime().toString();
                String[] split = backDateTime.substring(0, backDateTime.length() - 10).split("T");
                segment.DepDate = format.parse(split[0] + " " + split[1]);
                segment.OrgAirport = orderViewRS.getResponse().getDataLists().getPaxSegmentList().getPaxSegment().get(1).getDep().getIATALocationCode();
                segment.DstAirport = orderViewRS.getResponse().getDataLists().getPaxSegmentList().getPaxSegment().get(1).getArrival().getIATALocationCode();
                response.ListBackSegment.add(segment);
            }

            //返回的错误代码及错误信息
            /*ErrorsType errorsTypes = null;
            for (ErrorsType errorsType : orderRetrieveResponse.getIATAOrderViewRS().getError()) {
                errorsTypes = errorsType;
                ErrorType errorTypes = new ErrorType();
                MoResponse moResponse = new MoResponse();
                for (ErrorType errorType : errorsType.getError()) {
                    errorTypes.setCode(errorType.getCode());
                    errorTypes.setStatusText(errorType.getStatusText());
                    moResponse.ErrorCode = errorType.getCode();
                    moResponse.ErrorMsg = errorType.getStatusText();
                    response.ErrorCode = moResponse.ErrorCode;
                    response.ErrorMsg = moResponse.ErrorMsg;
                }
                if (errorTypes != null) {
                    errorsType.getError().add(errorTypes);
                }
            }
            orderViewRS.getError().add(errorsTypes);*/

            //订单号、订单支付状态......
            /*com.ktgj.common.spring.entity.iata.iata_orderviewrs.OrderType types = new com.ktgj.common.spring.entity.iata.iata_orderviewrs.OrderType();
            for (com.ktgj.common.spring.entity.iata.iata_orderviewrs.OrderType type : orderRetrieveResponse.getIATAOrderViewRS().getResponse().getOrder()) {
                //订单号
                types.setOrderID(type.getOrderID());
                response.OrderID = type.getOrderID();

                //TODO 订单支付状态未添加到response中        ContactInfoRefID指向DataList（下单人联系方式）
                types.setStatusCode(type.getStatusCode()); //订单支付状态

                com.ktgj.common.spring.entity.interfaces.AmountType amountType = new com.ktgj.common.spring.entity.interfaces.AmountType();
                amountType.setCurCode(type.getTotalPrice().getTotalAmount().getCurCode()); //货币种类
                amountType.setValue(type.getTotalPrice().getTotalAmount().getValue()); //订单总金额
                com.ktgj.common.spring.entity.iata.iata_orderviewrs.PriceType priceType = new com.ktgj.common.spring.entity.iata.iata_orderviewrs.PriceType();
                priceType.setTotalAmount(amountType);
                types.setTotalPrice(priceType);
                response.Amount = type.getTotalPrice().getTotalAmount().getValue();

                com.ktgj.common.spring.entity.iata.iata_orderviewrs.OrderItemType orderItemTypes = new com.ktgj.common.spring.entity.iata.iata_orderviewrs.OrderItemType();
                for (com.ktgj.common.spring.entity.iata.iata_orderviewrs.OrderItemType orderItemType : type.getOrderItem()) {
                    orderItemTypes.setOrderItemID(orderItemType.getOrderItemID()); //订单明细ID
                    response.BasicOrderInfo.OrderItemID = orderItemType.getOrderItemID();
                    //TODO 机票状态未添加到response中    时间获取未成功
                    orderItemTypes.setStatusCode(orderItemType.getStatusCode()); //机票状态

                    orderItemTypes.setCreationDateTime(orderItemType.getCreationDateTime()); //订单预定时间
                    response.BasicOrderInfo.CreationDateTime = orderItemType.getCreationDateTime().toString();

                    com.ktgj.common.spring.entity.interfaces.AmountType amountType1 = new com.ktgj.common.spring.entity.interfaces.AmountType();
                    amountType1.setValue(orderItemType.getPrice().getBaseAmount().getValue()); //票面价
                    com.ktgj.common.spring.entity.iata.iata_orderviewrs.PriceType priceType1 = new com.ktgj.common.spring.entity.iata.iata_orderviewrs.PriceType();
                    priceType1.setBaseAmount(amountType1);
                    orderItemTypes.setPrice(priceType1);

                    MoSegment moSegment = new MoSegment();
                    moSegment.PrintPrice = orderItemType.getPrice().getBaseAmount().getValue();
                    com.ktgj.common.spring.entity.iata.iata_orderviewrs.TaxSummaryType taxSummaryTypes = null;
                    for (com.ktgj.common.spring.entity.iata.iata_orderviewrs.TaxSummaryType taxSummaryType : orderItemType.getPrice().getTaxSummary()) {
                        taxSummaryTypes = taxSummaryType;
                        com.ktgj.common.spring.entity.iata.iata_orderviewrs.TaxType taxs = new com.ktgj.common.spring.entity.iata.iata_orderviewrs.TaxType();
                        for (com.ktgj.common.spring.entity.iata.iata_orderviewrs.TaxType tax : taxSummaryType.getTax()) {
                            taxs.setTaxCode(tax.getTaxCode()); //燃油费YQ 机建费 CN 其他税费（总和）
                            com.ktgj.common.spring.entity.interfaces.AmountType amountType2 = new com.ktgj.common.spring.entity.interfaces.AmountType();
                            amountType2.setValue(tax.getAmount().getValue());
                            taxs.setAmount(amountType2);
                            if ("YQ".equals(tax.getTaxCode())) {
                                moSegment.OilFee = tax.getAmount().getValue();
                            } else if ("CN".equals(tax.getTaxCode())) {
                                moSegment.Tax = tax.getAmount().getValue();
                            }
                        }
                        if (taxs != null) {
                            taxSummaryType.getTax().add(taxs);
                        }
                    }
                    orderItemType.getPrice().getTaxSummary().add(taxSummaryTypes);
                    response.ListGoSegment.add(moSegment);

                    com.ktgj.common.spring.entity.iata.iata_orderviewrs.FeeType feeTypes = new com.ktgj.common.spring.entity.iata.iata_orderviewrs.FeeType();
                    for (com.ktgj.common.spring.entity.iata.iata_orderviewrs.FeeType feeType : orderItemType.getPrice().getFee()) {
                        feeTypes.setDesigText(feeType.getDesigText()); //航意险费用 X产品费总和（含取消险费用、逾重行李费、选座费用等）支付渠道手续费
                        com.ktgj.common.spring.entity.interfaces.AmountType amountType3 = new com.ktgj.common.spring.entity.interfaces.AmountType();
                        amountType3.setValue(feeType.getAmount().getValue()); //金额
                        feeTypes.setAmount(amountType3);
                    }
                    if (feeTypes != null) {
                        orderItemType.getPrice().getFee().add(feeTypes);
                    }
                }
                if (orderItemTypes != null) {
                    type.getOrderItem().add(orderItemTypes);
                }
            }
            com.ktgj.common.spring.entity.iata.iata_orderviewrs.ResponseType responseType = new com.ktgj.common.spring.entity.iata.iata_orderviewrs.ResponseType();
            if (types != null) {
                responseType.getOrder().add(types);
            }
            orderViewRS.setResponse(responseType);

            IATAOrderViewRS orderViewRS1 = new IATAOrderViewRS();
            ContactInfoType contactInfoTypes = null;
            ResponseType responseType1 = new ResponseType();
            for (ContactInfoType contactInfoType : orderRetrieveResponse.getIATAOrderViewRS().getResponse().getDataLists().getContactInfoList().getContactInfo()) {
                contactInfoTypes = contactInfoType;
                contactInfoTypes.setContactInfoID(contactInfoType.getContactInfoID()); //自定义id

                IndividualType individualType = new IndividualType();
                individualType.setSurname(contactInfoType.getIndividual().getSurname()); //下单人姓名
                contactInfoTypes.setIndividual(individualType);
                response.Contacts.ContactName = contactInfoType.getIndividual().getSurname();

                PhoneType phoneTypes = new PhoneType();
                for (PhoneType phoneType : contactInfoType.getPhone()) {
                    phoneTypes.setPhoneNumber(phoneType.getPhoneNumber()); //下单人手机号
                    response.Contacts.ContactMobile = phoneType.getPhoneNumber().toString();
                }
                contactInfoType.getPhone().add(phoneTypes);
                ContactInfoListType contactInfoListType = new ContactInfoListType();
                contactInfoListType.getContactInfo().add(contactInfoTypes);
                com.ktgj.common.spring.entity.iata.iata_orderviewrs.DataListsType dataListsType = new com.ktgj.common.spring.entity.iata.iata_orderviewrs.DataListsType();
                dataListsType.setContactInfoList(contactInfoListType);
                responseType1.setDataLists(dataListsType);
            }
            orderViewRS1.setResponse(responseType1);

            IATAOrderViewRS orderViewRS2 = new IATAOrderViewRS();
            ResponseType responseType2 = new ResponseType();
            MoSegment moSegment = new MoSegment();
            com.ktgj.common.spring.entity.iata.iata_orderviewrs.DataListsType dataListsType = new com.ktgj.common.spring.entity.iata.iata_orderviewrs.DataListsType();
            com.ktgj.common.spring.entity.iata.iata_orderviewrs.PaxSegmentListType paxSegmentListType = new com.ktgj.common.spring.entity.iata.iata_orderviewrs.PaxSegmentListType();
            com.ktgj.common.spring.entity.iata.iata_orderviewrs.PaxSegmentType paxSegmentTypes = new com.ktgj.common.spring.entity.iata.iata_orderviewrs.PaxSegmentType();
            com.ktgj.common.spring.entity.iata.iata_orderviewrs.TransportArrivalType arrivalType = new com.ktgj.common.spring.entity.iata.iata_orderviewrs.TransportArrivalType();
            com.ktgj.common.spring.entity.iata.iata_orderviewrs.TransportDepType depType = new com.ktgj.common.spring.entity.iata.iata_orderviewrs.TransportDepType();
            for (com.ktgj.common.spring.entity.iata.iata_orderviewrs.PaxSegmentType paxSegmentType : orderRetrieveResponse.getIATAOrderViewRS().getResponse().getDataLists().getPaxSegmentList().getPaxSegment()) {
                arrivalType.setIATALocationCode(paxSegmentType.getArrival().getIATALocationCode()); //机场三字码
                arrivalType.setStationName(paxSegmentType.getArrival().getStationName()); //机场名称
                paxSegmentTypes.setArrival(arrivalType);

                depType.setIATALocationCode(paxSegmentType.getDep().getIATALocationCode()); //机场三字码
                paxSegmentTypes.setDep(depType);

                paxSegmentListType.getPaxSegment().add(paxSegmentTypes);
                dataListsType.setPaxSegmentList(paxSegmentListType);
                responseType2.setDataLists(dataListsType);

                moSegment.DstAirport = paxSegmentType.getArrival().getIATALocationCode();
                moSegment.OrgAirport = paxSegmentType.getDep().getIATALocationCode();
            }
            orderViewRS2.setResponse(responseType2);
            response.ListGoSegment.add(moSegment);

            IATAOrderViewRS orderViewRS3 = new IATAOrderViewRS();
            ResponseType responseType3 = new ResponseType();
            com.ktgj.common.spring.entity.iata.iata_orderviewrs.DataListsType dataListsType1 = new com.ktgj.common.spring.entity.iata.iata_orderviewrs.DataListsType();
            com.ktgj.common.spring.entity.iata.iata_orderviewrs.PaxListType paxListType = new com.ktgj.common.spring.entity.iata.iata_orderviewrs.PaxListType();
            MoPassenger moPassenger = new MoPassenger();
            com.ktgj.common.spring.entity.iata.iata_orderviewrs.PaxType paxs = new com.ktgj.common.spring.entity.iata.iata_orderviewrs.PaxType();
            IndividualType individualType = new IndividualType();

            for (com.ktgj.common.spring.entity.iata.iata_orderviewrs.PaxType pax : orderRetrieveResponse.getIATAOrderViewRS().getResponse().getDataLists().getPaxList().getPax()) {
                MeasureType measureType = new MeasureType();
                measureType.setValue(pax.getAgeMeasure().getValue());
                paxs.setAgeMeasure(measureType); //年龄
                paxs.setCitizenshipCountryCode(pax.getCitizenshipCountryCode()); //国籍三字码
                paxs.setBirthdate(pax.getBirthdate()); //生日

                paxListType.getPax().add(paxs);
                dataListsType1.setPaxList(paxListType);
                responseType3.setDataLists(dataListsType1);

                individualType.setSurname(pax.getIndividual().getSurname()); //姓名
                individualType.setGenderCode(pax.getIndividual().getGenderCode()); //性别
                pax.setIndividual(individualType);
                moPassenger.PassengerName = pax.getIndividual().getSurname();

                IdentityDocType identityDocTypes = new IdentityDocType();
                for (IdentityDocType identityDocType : pax.getIdentityDoc()) {
                    identityDocTypes.setIdentityDocID(identityDocType.getIdentityDocID()); //证件号
                    identityDocTypes.setIdentityDocTypeCode(identityDocType.getIdentityDocTypeCode()); //证件类型
                    moPassenger.IDNO = identityDocType.getIdentityDocID();
                    moPassenger.IDType = Integer.parseInt(identityDocType.getIdentityDocTypeCode());
                }
                pax.getIdentityDoc().add(identityDocTypes);
            }
            orderViewRS3.setResponse(responseType3);
            response.ListMoPassenger.add(moPassenger);*/
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        }
        return response;
    }

    /**
     * 取消预定
     *
     * @param request
     * @return
     */
    public MoCancelOrderResponse _CancelOrder(MoCancelOrderRequest request) {
        MoCancelOrderResponse response = new MoCancelOrderResponse();
        IATAOrderCancelRQ orderCancelRQ = new IATAOrderCancelRQ();
        com.ktgj.common.spring.entity.iata.iata_ordercancelrq.CountryType countryType = new com.ktgj.common.spring.entity.iata.iata_ordercancelrq.CountryType();
        PointofSaleType pointofSaleType = new PointofSaleType();
        com.ktgj.common.spring.entity.iata.iata_ordercancelrq.RequestType requestType = new com.ktgj.common.spring.entity.iata.iata_ordercancelrq.RequestType();
        com.ktgj.common.spring.entity.iata.iata_ordercancelrq.OrderType orderType = new com.ktgj.common.spring.entity.iata.iata_ordercancelrq.OrderType();

        countryType.setCountryCode("CN");
        pointofSaleType.setCountry(countryType);
        orderCancelRQ.setPointOfSale(pointofSaleType);
        orderType.setOrderID(request.ListOrderItem.OrderID); //唯一订单标识 必传
        orderType.setOwnerCode("9C"); //分配给承运人的航空公司代码 icao定义的3个字符代码或iata定义的2个字符代码 必传
        requestType.getOrder().add(orderType);
        orderCancelRQ.setRequest(requestType);

        OrderCancel orderCancel = new OrderCancel();
        orderCancel.setIATAOrderCancelRQ(orderCancelRQ);
        //URL url;
        try {
            /*url = new URL(s_JsonUrl);
            QName qname = new QName("http://www.interfaces.gds.ch.com", "TmcWebServiceImplService");
            TmcWebServiceImplService service = new TmcWebServiceImplService(url, qname);
            TmcWebService tmcWebService = service.getTmcWebServiceImplPort();

            BindingProvider bp = (BindingProvider) tmcWebService;
            bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, userName);
            bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, passWord);
            bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, s_JsonUrl);
            OrderCancelResponse orderCancelResponse = tmcWebService.orderCancel(orderCancel);
            System.out.println(orderCancelResponse.getIATAOrderCancelRS().getError().get(0));*/

            SpringTokenResponse tokenResponse = getToken();
            String urlInfo = this.s_JsonUrl + "apiOrder/ota/orderOtaCtr/orderCancel";
            if (!tokenResponse.getIfSuccess().equals("Y"))
            {
                response.ErrorMsg = "获取Token失败";
                response.ErrorCode = (EnumHelper.ReturnCode.系统异常代码).toString();
                response.IsSuccess = false;
            }
            HashMap<String,String> header = new HashMap<>();
            header.put("accessToken", tokenResponse.getOauth2ResultDTO().getAccessToken());
            String result = HttpClientUtil.doPostJsonWithHeaderMap(urlInfo, JSON.toJSONString(orderCancelRQ), header);
            IATAOrderCancelRS orderCancelRS = JSON.parseObject(result, IATAOrderCancelRS.class);
            /*com.ktgj.common.spring.entity.iata.iata_ordercancelrs.ErrorType errorTypes = new com.ktgj.common.spring.entity.iata.iata_ordercancelrs.ErrorType();
            MoResponse moResponse = new MoResponse();
            for (com.ktgj.common.spring.entity.iata.iata_ordercancelrs.ErrorType errorType : orderCancelResponse.getIATAOrderCancelRS().getError()) {
                errorTypes.setDescText(errorType.getDescText());
                errorTypes.setStatusText(errorType.getStatusText());
                moResponse.ErrorCode = errorType.getDescText();
                moResponse.ErrorMsg = errorType.getStatusText();
                response.ErrorCode = moResponse.ErrorCode;
                response.ErrorMsg = moResponse.ErrorMsg;
            }
            if (errorTypes != null) {
                orderCancelRS.getError().add(errorTypes);
            }*/
            if (orderCancelRS.getError().size() > 0) {
                if (orderCancelRS.getError().get(0).getStatusText().equals("Y")) {
                    response.IsSuccess = true;
                } else {
                    response.IsSuccess = false;
                }
                response.ErrorCode = orderCancelRS.getError().get(0).getCode();
                response.ErrorMsg = orderCancelRS.getError().get(0).getDescText();
            }
        } catch (Exception e) {
            e.getStackTrace();
        }
        return response;
    }

    /**
     * 支付初始化 获取支付流水
     * 商旅通支付
     *
     * @param request
     * @return
     */
    public MoOrderPayResponse _OrderPay(MoOrderPayRequest request) {
        MoOrderPayResponse response = new MoOrderPayResponse();
        if (request.RequestType == EnumHelper.RequestType.Spring && StringUtils.isEmpty(request.OrderID)) {
            response.ErrorMsg = "商户订单号-不能为空";
            response.IsSuccess = false;
            return response;
        }
        if (StringUtils.isEmpty(request.PayAmount.toString())) {
            response.ErrorMsg = "支付金额-不能为空";
            response.IsSuccess = false;
            return response;
        }
        String orderId = request.OrderID;
        long txnAmt = request.PayAmount.longValue();

        StringBuilder builder = new StringBuilder();

        builder.append(partner);
        builder.append(orderId);
        builder.append(txnAmt);
        String signMsg = signMsgs(builder.toString(), key);

        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(String.format("partner=%s", partner));
        stringBuilder.append(String.format("&orderId=%s", orderId));
        stringBuilder.append(String.format("&txnAmt=%s", txnAmt));
        stringBuilder.append(String.format("&signMsg=%s", signMsg));
        try {
            Map<String, String> post = _Yeepay.httpRequest(payURL, stringBuilder.toString(), "POST", "UTF-8");
            Set<String> set = post.keySet();
            Iterator<String> iterator = set.iterator();
            while (iterator.hasNext()) {
                String next = iterator.next();
                System.out.println("Key：" + next);
                System.out.println("Value：" + post.get(next));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return response;
    }

    /**
     * 退票-计算退票费用
     *
     * @param request
     * @return
     */
    public MoOrderRefundCaltResponse _OrderRefundCalt(MoOrderRefundCaltRequest request) {
        MoOrderRefundCaltResponse response = new MoOrderRefundCaltResponse();
        IATAOrderReshopRQ orderReshopRQ = new IATAOrderReshopRQ();
        com.ktgj.common.spring.entity.iata.iata_orderreshoprq.CountryType countryType = new com.ktgj.common.spring.entity.iata.iata_orderreshoprq.CountryType();
        com.ktgj.common.spring.entity.iata.iata_orderreshoprq.MessageDocType messageDocType = new com.ktgj.common.spring.entity.iata.iata_orderreshoprq.MessageDocType();
        com.ktgj.common.spring.entity.iata.iata_orderreshoprq.POSType posType = new com.ktgj.common.spring.entity.iata.iata_orderreshoprq.POSType();
        com.ktgj.common.spring.entity.iata.iata_orderreshoprq.RequestType requestType = new com.ktgj.common.spring.entity.iata.iata_orderreshoprq.RequestType();
        UpdateOrderType updateOrderType = new UpdateOrderType();
        ReshopOrderType reshopOrderType = new ReshopOrderType();
        ServiceOrderType serviceOrderType = new ServiceOrderType();
        DeleteOrderItemType deleteOrderItemType = new DeleteOrderItemType();

        messageDocType.setName("ndc");
        messageDocType.setRefVersionNumber(BigDecimal.valueOf(18.2));
        orderReshopRQ.setMessageDoc(messageDocType);

        countryType.setCountryCode("CN");
        countryType.setCountryName("China");
        posType.setCountry(countryType);
        orderReshopRQ.setPointOfSale(posType);

        deleteOrderItemType.setOrderItemRefID(request.OutOrderID); //该订单中待删除的明细id, RS将根据这些明细id,计算出 取消的费用/退款
        serviceOrderType.getDeleteOrderItem().add(deleteOrderItemType);
        reshopOrderType.setServiceOrder(serviceOrderType);
        updateOrderType.setReshopOrder(reshopOrderType);
        requestType.setUpdateOrder(updateOrderType);
        orderReshopRQ.setRequest(requestType);

        OrderReshopForRefund orderReshopForRefund = new OrderReshopForRefund();
        orderReshopForRefund.setIATAOrderReshopRQ(orderReshopRQ);

        //URL url;
        try {
            /*url = new URL(s_JsonUrl);
            QName qname = new QName("http://www.interfaces.gds.ch.com", "TmcWebServiceImplService");
            TmcWebServiceImplService service = new TmcWebServiceImplService(url, qname);
            TmcWebService tmcWebService = service.getTmcWebServiceImplPort();

            BindingProvider bp = (BindingProvider) tmcWebService;
            bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, userName);
            bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, passWord);
            bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, s_JsonUrl);
            OrderReshopForRefundResponse orderReshopForRefundResponse = tmcWebService.orderReshopForRefund(orderReshopForRefund);
            System.out.println(orderReshopForRefundResponse.getIATAOrderReshopRS().getResponse().getReshopResults().getReshopOffers().getOffer().get(0));*/

            SpringTokenResponse tokenResponse = getToken();
            String urlInfo = this.s_JsonUrl + "apiOrder/ota/orderOtaCtr/orderReshopForRefund";
            if (!tokenResponse.getIfSuccess().equals("Y"))
            {
                response.ErrorMsg = "获取Token失败";
                response.ErrorCode = (EnumHelper.ReturnCode.系统异常代码).toString();
                response.IsSuccess = false;
            }
            HashMap<String,String> header = new HashMap<>();
            header.put("accessToken", tokenResponse.getOauth2ResultDTO().getAccessToken());
            String result = HttpClientUtil.doPostJsonWithHeaderMap(urlInfo, JSON.toJSONString(orderReshopRQ), header);
            IATAOrderReshopRS orderReshopRS = JSON.parseObject(result, IATAOrderReshopRS.class);

            if (orderReshopRS.getError() != null && orderReshopRS.getError().size() > 0) {
                if (orderReshopRS.getError().get(0).getCode() != null && !orderReshopRS.getError().get(0).getCode().equals("") &&
                        orderReshopRS.getError().get(0).getDescText() != null && !orderReshopRS.getError().get(0).getDescText().equals("")) {
                    response.ErrorCode = orderReshopRS.getError().get(0).getCode();
                    response.ErrorMsg = orderReshopRS.getError().get(0).getDescText();
                    response.IsSuccess = false;
                    return response;
                }
            }
            //TODO 未完成
            /*com.ktgj.common.spring.entity.iata.iata_orderreshoprs.ResponseType responseType = new com.ktgj.common.spring.entity.iata.iata_orderreshoprs.ResponseType();
            ReshopResultsType resultsType = new ReshopResultsType();
            ReshopOffersType offersType = new ReshopOffersType();
            BasicOrderInfo basicOrderInfo = new BasicOrderInfo();
            TicketOrderDetailRefundModel model = new TicketOrderDetailRefundModel();
            com.ktgj.common.spring.entity.iata.iata_orderreshoprs.Offer1Type offer1Types = new com.ktgj.common.spring.entity.iata.iata_orderreshoprs.Offer1Type();
            for (com.ktgj.common.spring.entity.iata.iata_orderreshoprs.Offer1Type offer1Type : orderReshopForRefundResponse.getIATAOrderReshopRS().getResponse().getReshopResults().getReshopOffers().getOffer()) {
                offer1Types = offer1Type;
                com.ktgj.common.spring.entity.iata.iata_orderreshoprs.DeleteOrderItemType orderItemTypes = new com.ktgj.common.spring.entity.iata.iata_orderreshoprs.DeleteOrderItemType();
                for (com.ktgj.common.spring.entity.iata.iata_orderreshoprs.DeleteOrderItemType orderItemType : offer1Type.getDeleteOrderItem()) {
                    orderItemTypes.setOrderItemRefID(orderItemType.getOrderItemRefID()); //订单明细id

                    com.ktgj.common.spring.entity.interfaces.AmountType amountType = new com.ktgj.common.spring.entity.interfaces.AmountType();
                    amountType.setValue(orderItemType.getDifferentialAmountDue().getAmount().getValue()); //净退金额
                    ReshopDifferentialType differentialType = new ReshopDifferentialType();
                    differentialType.setAmount(amountType);
                    orderItemTypes.setDifferentialAmountDue(differentialType);

                    com.ktgj.common.spring.entity.interfaces.AmountType amountTypes = new com.ktgj.common.spring.entity.interfaces.AmountType();
                    amountTypes.setValue(orderItemType.getFeesDifferential().getAmount().getValue()); //手续费总额
                    ReshopDifferentialType differentialTypes = new ReshopDifferentialType();
                    differentialTypes.setAmount(amountTypes);
                    orderItemTypes.setFeesDifferential(differentialTypes);

                    com.ktgj.common.spring.entity.interfaces.AmountType amountType1 = new com.ktgj.common.spring.entity.interfaces.AmountType();
                    amountType1.setValue(orderItemType.getOriginalOrderItemDifferential().getAmount().getValue()); //退款票价
                    ReshopDifferentialType differentialType1 = new ReshopDifferentialType();
                    differentialType1.setAmount(amountType1);
                    com.ktgj.common.spring.entity.iata.iata_orderreshoprs.TaxSummaryType taxSummaryType = new com.ktgj.common.spring.entity.iata.iata_orderreshoprs.TaxSummaryType();
                    com.ktgj.common.spring.entity.interfaces.AmountType amountType2 = new com.ktgj.common.spring.entity.interfaces.AmountType();
                    amountType2.setValue(orderItemType.getOriginalOrderItemDifferential().getTaxSummary().getTotalTaxAmount().getValue()); //税费总额
                    taxSummaryType.setTotalTaxAmount(amountType2);
                    differentialType1.setTaxSummary(taxSummaryType);

                    com.ktgj.common.spring.entity.iata.iata_orderreshoprs.TaxSummaryType type = new com.ktgj.common.spring.entity.iata.iata_orderreshoprs.TaxSummaryType();
                    com.ktgj.common.spring.entity.interfaces.TaxType taxs = new com.ktgj.common.spring.entity.interfaces.TaxType();
                    for (com.ktgj.common.spring.entity.interfaces.TaxType tax : orderItemType.getOriginalOrderItemDifferential().getTaxSummary().getTax()) {
                        com.ktgj.common.spring.entity.interfaces.AmountType amountType3 = new com.ktgj.common.spring.entity.interfaces.AmountType();
                        amountType3.setValue(tax.getAmount().getValue()); //CN-机场建设费 YQ-国内燃油附加税 YR-国际燃油附加税
                        taxs.setAmount(amountType3);
                        taxs.setTaxCode(tax.getTaxCode());
                        if ("CN".equals(tax.getTaxCode())) {
                            model.TotalAirportPrice = tax.getAmount().getValue();
                        } else if ("YQ".equals(tax.getTaxCode())) {
                            model.TotalFuelPrice = tax.getAmount().getValue();
                        }
                    }
                    type.getTax().add(taxs);
                    differentialType1.setTaxSummary(type);

                    orderItemTypes.setOriginalOrderItemDifferential(differentialType1);

                    basicOrderInfo.OrderItemID = orderItemType.getOrderItemRefID(); //订单明细id
                    model.RefundPrice = orderItemType.getDifferentialAmountDue().getAmount().getValue(); //净退金额
                    model.TotalTicketPrice = orderItemType.getOriginalOrderItemDifferential().getAmount().getValue();
                    response.basicOrderInfo = basicOrderInfo;
                    response.detailRefundModel = model;
                    response.RefundFee = orderItemType.getFeesDifferential().getAmount().getValue(); //手续费总额
                }
                offer1Type.getDeleteOrderItem().add(orderItemTypes);
            }

            offersType.getOffer().add(offer1Types);
            resultsType.setReshopOffers(offersType);
            responseType.setReshopResults(resultsType);
            orderReshopRS.setResponse(responseType);*/
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
        return response;
    }

    /**
     * 退票-提交退票申请
     *
     * @param request
     * @return
     */
    public MoOrderRefundResponse _OrderRefund(MoOrderRefundRequest request) {
        MoOrderRefundResponse response = new MoOrderRefundResponse();
        IATAOrderChangeRQ changeRQ = new IATAOrderChangeRQ();
        com.ktgj.common.spring.entity.iata.iata_orderchangerq.MessageDocType messageDocType = new com.ktgj.common.spring.entity.iata.iata_orderchangerq.MessageDocType();
        com.ktgj.common.spring.entity.iata.iata_orderchangerq.POSType posType = new com.ktgj.common.spring.entity.iata.iata_orderchangerq.POSType();
        com.ktgj.common.spring.entity.iata.iata_orderchangerq.CountryType countryType = new com.ktgj.common.spring.entity.iata.iata_orderchangerq.CountryType();
        com.ktgj.common.spring.entity.iata.iata_orderchangerq.RequestType requestType = new com.ktgj.common.spring.entity.iata.iata_orderchangerq.RequestType();
        ChangeOrderType changeOrderType = new ChangeOrderType();
        UpdateOrderItemType updateOrderItemType = new UpdateOrderItemType();
        com.ktgj.common.spring.entity.iata.iata_orderchangerq.DeleteOrderItemType deleteOrderItemType = new com.ktgj.common.spring.entity.iata.iata_orderchangerq.DeleteOrderItemType();

        messageDocType.setName("ndc");
        messageDocType.setRefVersionNumber(BigDecimal.valueOf(18.2));
        changeRQ.setMessageDoc(messageDocType);

        countryType.setCountryCode("CN");
        countryType.setCountryName("China");
        posType.setCountry(countryType);
        changeRQ.setPointOfSale(posType);

        deleteOrderItemType.getOrderItemRefID().add(request.OrderID);
        updateOrderItemType.setDeleteOrderItem(deleteOrderItemType);
        changeOrderType.setUpdateOrderItem(updateOrderItemType);
        requestType.setChangeOrder(changeOrderType);
        changeRQ.setRequest(requestType);

        OrderChangeForRefund orderChangeForRefund = new OrderChangeForRefund();
        orderChangeForRefund.setIATAOrderChangeRQ(changeRQ);

        URL url;
        try {
            url = new URL(s_JsonUrl);
            QName qname = new QName("http://www.interfaces.gds.ch.com", "TmcWebServiceImplService");
            TmcWebServiceImplService service = new TmcWebServiceImplService(url, qname);
            TmcWebService tmcWebService = service.getTmcWebServiceImplPort();

            BindingProvider bp = (BindingProvider) tmcWebService;
            bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, userName);
            bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, passWord);
            bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, s_JsonUrl);
            OrderChangeForRefundResponse orderChangeForRefundResponse = tmcWebService.orderChangeForRefund(orderChangeForRefund);
            System.out.println(orderChangeForRefundResponse.getIATAOrderViewRS().getResponse().getOrderAmendment().get(0));

            IATAOrderViewRS orderViewRS = new IATAOrderViewRS();
            ResponseType responseType = new ResponseType();
            OrderAmendmentType orderAmendmentTypes = new OrderAmendmentType();
            for (OrderAmendmentType orderAmendmentType : orderChangeForRefundResponse.getIATAOrderViewRS().getResponse().getOrderAmendment()) {
                orderAmendmentTypes.setActionTypeCode(orderAmendmentType.getActionTypeCode()); //操作类型
                orderAmendmentTypes.setOfferItemRefID(orderAmendmentType.getOfferItemRefID()); //退款申请id字符串(用于后续扩展退款对账接口)，格式：机票明细ID1_退款申请ID1
                response.FlowID = orderAmendmentType.getOfferItemRefID();
            }
            responseType.getOrderAmendment().add(orderAmendmentTypes);
            orderViewRS.setResponse(responseType);
            orderChangeForRefundResponse.setIATAOrderViewRS(orderViewRS);
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
        return response;
    }

    /**
     * 变更-查询可变更航班
     *
     * @param request
     * @return
     */
    public MoFlightSearchResponse _orderReshopForChange(MoRescheduleSearchRequest request) {
        MoFlightSearchResponse response = new MoFlightSearchResponse();
        IATAOrderReshopRQ orderReshopRQ = new IATAOrderReshopRQ();
        com.ktgj.common.spring.entity.iata.iata_orderreshoprq.MessageDocType messageDocType = new com.ktgj.common.spring.entity.iata.iata_orderreshoprq.MessageDocType();
        com.ktgj.common.spring.entity.iata.iata_orderreshoprq.POSType posType = new com.ktgj.common.spring.entity.iata.iata_orderreshoprq.POSType();
        com.ktgj.common.spring.entity.iata.iata_orderreshoprq.CountryType countryType = new com.ktgj.common.spring.entity.iata.iata_orderreshoprq.CountryType();
        com.ktgj.common.spring.entity.iata.iata_orderreshoprq.RequestType requestType = new com.ktgj.common.spring.entity.iata.iata_orderreshoprq.RequestType();
        UpdateOrderType updateOrderType = new UpdateOrderType();
        ReshopOrderType orderType = new ReshopOrderType();
        ServiceOrderType serviceOrderType = new ServiceOrderType();
        AddOfferItemsType offerItemsType = new AddOfferItemsType();
        com.ktgj.common.spring.entity.iata.iata_orderreshoprq.FlightRequestType flightRequestType = new com.ktgj.common.spring.entity.iata.iata_orderreshoprq.FlightRequestType();
        com.ktgj.common.spring.entity.iata.iata_orderreshoprq.OriginDestCriteriaType originDestCriteriaType = new com.ktgj.common.spring.entity.iata.iata_orderreshoprq.OriginDestCriteriaType();
        com.ktgj.common.spring.entity.iata.iata_orderreshoprq.OriginDepCriteriaType originDepCriteriaType = new com.ktgj.common.spring.entity.iata.iata_orderreshoprq.OriginDepCriteriaType();
        DeleteOrderItemType deleteOrderItemType = new DeleteOrderItemType();

        messageDocType.setName("ndc");
        messageDocType.setRefVersionNumber(BigDecimal.valueOf(18.2));
        orderReshopRQ.setMessageDoc(messageDocType);

        countryType.setCountryCode("CN");
        countryType.setCountryName("China");
        posType.setCountry(countryType);
        orderReshopRQ.setPointOfSale(posType);

        requestType.setOrderRefID(request.OrderID); //订单号
        originDepCriteriaType.setDate(request.DepartDate); //计划变更到的航班日期
        originDestCriteriaType.setOriginDepCriteria(originDepCriteriaType);
        flightRequestType.getOriginDestCriteria().add(originDestCriteriaType);
        offerItemsType.setFlightCriteria(flightRequestType);
        serviceOrderType.setAddOfferItems(offerItemsType);

        deleteOrderItemType.setOrderItemRefID(request.orderIteamId); //待变更的订单明细id
        serviceOrderType.getDeleteOrderItem().add(deleteOrderItemType);

        orderType.setServiceOrder(serviceOrderType);
        updateOrderType.setReshopOrder(orderType);
        requestType.setUpdateOrder(updateOrderType);
        orderReshopRQ.setRequest(requestType);

        OrderReshopForChange forChange = new OrderReshopForChange();
        forChange.setIATAOrderReshopRQ(orderReshopRQ);

        URL url;
        try {
            url = new URL(s_JsonUrl);
            QName qname = new QName("http://www.interfaces.gds.ch.com", "TmcWebServiceImplService");
            TmcWebServiceImplService service = new TmcWebServiceImplService(url, qname);
            TmcWebService tmcWebService = service.getTmcWebServiceImplPort();

            BindingProvider bp = (BindingProvider) tmcWebService;
            bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, userName);
            bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, passWord);
            bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, s_JsonUrl);
            OrderReshopForChangeResponse orderReshopForChangeResponse = tmcWebService.orderReshopForChange(forChange);
            System.out.println(orderReshopForChangeResponse.getIATAOrderReshopRS().getResponse());

            for (com.ktgj.common.spring.entity.iata.iata_orderreshoprs.PaxSegmentType paxSegmentType : orderReshopForChangeResponse.getIATAOrderReshopRS().getResponse().getDataLists().getPaxSegmentList().getPaxSegment()) {
                MoFlightInfo moFlightInfo = new MoFlightInfo();
                moFlightInfo.PaxSegmentRefID = paxSegmentType.getPaxSegmentID(); //航段id
                moFlightInfo.DstAirport = paxSegmentType.getArrival().getIATALocationCode(); //抵达机场三字码
                moFlightInfo.DstAirportName = paxSegmentType.getArrival().getStationName(); //抵达机场名称
                moFlightInfo.OrgAirport = paxSegmentType.getDep().getIATALocationCode(); //出发机场三字码
                moFlightInfo.OrgAirportName = paxSegmentType.getDep().getStationName(); //出发机场名称
                moFlightInfo.Airline = paxSegmentType.getOperatingCarrierInfo().getCarrierDesigCode(); //航空公司代码
                moFlightInfo.FlightNo = paxSegmentType.getOperatingCarrierInfo().getOperatingCarrierFlightNumberText(); //航班号
                response.ListGoFlightInfo.add(moFlightInfo);
            }

            for (com.ktgj.common.spring.entity.iata.iata_orderreshoprs.Offer1Type offer1Type : orderReshopForChangeResponse.getIATAOrderReshopRS().getResponse().getReshopResults().getReshopOffers().getOffer()) {
                for (com.ktgj.common.spring.entity.iata.iata_orderreshoprs.OfferItemType offerItemType : offer1Type.getAddOfferItem()) {
                    MoCabinInfo moCabinInfo = new MoCabinInfo();
                    MoFlightInfo moFlightInfo = new MoFlightInfo();
                    moCabinInfo.DiffPriceAdt = offerItemType.getDifferentialAmountDue().getAmount().getValue(); //差价（升舱费）
                    for (com.ktgj.common.spring.entity.iata.iata_orderreshoprs.FareDetailType fareDetailType : offerItemType.getFareDetail()) {
                        for (com.ktgj.common.spring.entity.iata.iata_orderreshoprs.FareComponentType fareComponentType : fareDetailType.getFareComponent()) {
                            moCabinInfo.Cabin = fareComponentType.getCabinType().getCabinTypeCode(); //舱位
                            moFlightInfo.ListCabinInfo.add(moCabinInfo);
                            response.ListGoFlightInfo.add(moFlightInfo);
                        }
                    }
                }
            }
        } catch (Exception exception) {
            System.out.println(exception.getMessage());
        }
        return response;
    }

    /**
     * 变更-计算航班变更申请
     *
     * @param request
     * @return
     */
    public MoQueryOrderResponse _orderReshopGetPrice(MoRescheduleSearchRequest request) {
        MoQueryOrderResponse response = new MoQueryOrderResponse();
        IATAOrderReshopRQ orderReshopRQ = new IATAOrderReshopRQ();
        com.ktgj.common.spring.entity.iata.iata_orderreshoprq.MessageDocType messageDocType = new com.ktgj.common.spring.entity.iata.iata_orderreshoprq.MessageDocType();
        com.ktgj.common.spring.entity.iata.iata_orderreshoprq.POSType posType = new com.ktgj.common.spring.entity.iata.iata_orderreshoprq.POSType();
        com.ktgj.common.spring.entity.iata.iata_orderreshoprq.CountryType countryType = new com.ktgj.common.spring.entity.iata.iata_orderreshoprq.CountryType();
        com.ktgj.common.spring.entity.iata.iata_orderreshoprq.RequestType requestType = new com.ktgj.common.spring.entity.iata.iata_orderreshoprq.RequestType();
        UpdateOrderType updateOrderType = new UpdateOrderType();
        ReshopOrderType reshopOrderType = new ReshopOrderType();
        ServiceOrderType serviceOrderType = new ServiceOrderType();
        AddOfferItemsType addOfferItemsType = new AddOfferItemsType();
        com.ktgj.common.spring.entity.iata.iata_orderreshoprq.FlightRequestType flightRequestType = new com.ktgj.common.spring.entity.iata.iata_orderreshoprq.FlightRequestType();
        com.ktgj.common.spring.entity.iata.iata_orderreshoprq.AffinityRequestType affinityRequestType = new com.ktgj.common.spring.entity.iata.iata_orderreshoprq.AffinityRequestType();
        com.ktgj.common.spring.entity.iata.iata_orderreshoprq.KeyValuePropertyType keyValuePropertyType = new com.ktgj.common.spring.entity.iata.iata_orderreshoprq.KeyValuePropertyType();

        messageDocType.setName("ndc");
        messageDocType.setRefVersionNumber(BigDecimal.valueOf(18.2));
        orderReshopRQ.setMessageDoc(messageDocType);

        countryType.setCountryCode("CN");
        countryType.setCountryName("China");
        posType.setCountry(countryType);
        orderReshopRQ.setPointOfSale(posType);

        keyValuePropertyType.setKeyText(request.PaxSegmentID); //选中的航段id
        keyValuePropertyType.setValueText(request.orderIteamId); //订单明细id
        affinityRequestType.getKeywordPref().add(keyValuePropertyType);
        flightRequestType.setAffinityShoppingCriteria(affinityRequestType);
        addOfferItemsType.setFlightCriteria(flightRequestType);
        serviceOrderType.setAddOfferItems(addOfferItemsType);
        reshopOrderType.setServiceOrder(serviceOrderType);
        updateOrderType.setReshopOrder(reshopOrderType);
        requestType.setUpdateOrder(updateOrderType);
        orderReshopRQ.setRequest(requestType);

        OrderReshopGetPrice getPrice = new OrderReshopGetPrice();
        getPrice.setIATAOrderReshopRQ(orderReshopRQ);

        URL url;
        try {
            url = new URL(s_JsonUrl);
            QName qname = new QName("http://www.interfaces.gds.ch.com", "TmcWebServiceImplService");
            TmcWebServiceImplService service = new TmcWebServiceImplService(url, qname);
            TmcWebService tmcWebService = service.getTmcWebServiceImplPort();

            BindingProvider bp = (BindingProvider) tmcWebService;
            bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, userName);
            bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, passWord);
            bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, s_JsonUrl);
            OrderReshopGetPriceResponse orderReshopGetPriceResponse = tmcWebService.orderReshopGetPrice(getPrice);
            System.out.println(orderReshopGetPriceResponse.getIATAOrderReshopRS().getResponse());

            for (com.ktgj.common.spring.entity.iata.iata_orderreshoprs.PaxSegmentType paxSegmentType : orderReshopGetPriceResponse.getIATAOrderReshopRS().getResponse().getDataLists().getPaxSegmentList().getPaxSegment()) {
                MoSegment moSegment = new MoSegment();
                moSegment.SortNum = paxSegmentType.getPaxSegmentID(); //变更后的航段id
                moSegment.DstAirport = paxSegmentType.getArrival().getIATALocationCode(); //抵达机场三字码
                moSegment.OrgAirport = paxSegmentType.getDep().getIATALocationCode(); //出发机场三字码
                moSegment.Airline = paxSegmentType.getMarketingCarrierInfo().getCarrierDesigCode(); //航空公司二字码
                moSegment.FlightNo = paxSegmentType.getMarketingCarrierInfo().getMarketingCarrierFlightNumberText(); //航班号
                for (com.ktgj.common.spring.entity.iata.iata_orderreshoprs.DatedOperatingLegType datedOperatingLegType : paxSegmentType.getDatedOperatingLeg()) {
                    moSegment.PlaneStyle = datedOperatingLegType.getCarrierAircraftType().getCarrierAircraftTypeCode();
                }
                response.ListGoSegment.add(moSegment);
            }

            for (com.ktgj.common.spring.entity.iata.iata_orderreshoprs.PaxType pax : orderReshopGetPriceResponse.getIATAOrderReshopRS().getResponse().getDataLists().getPaxList().getPax()) {
                MoPassenger moPassenger = new MoPassenger();
                moPassenger.IDType = Integer.parseInt(pax.getFOID().getCreditCardIssuerCode()); //乘客证件类型
                moPassenger.IDNO = pax.getFOID().getFOIDID(); //乘客证件号码
                moPassenger.PassengerName = pax.getIndividual().getSurname(); //乘客姓名
                moPassenger.PsgID = pax.getPaxID(); //乘机人编号
                //乘客类型(成人>12岁=1,儿童2-12岁=2,婴儿2岁=3）
                if ("ADT".equals(pax.getPTC())) {
                    moPassenger.PassengerType = 1;
                } else if ("CHD".equals(pax.getPTC())) {
                    moPassenger.PassengerType = 2;
                } else if ("INF".equals(pax.getPTC())) {
                    moPassenger.PassengerType = 3;
                }
                response.ListMoPassenger.add(moPassenger);
            }

            for (com.ktgj.common.spring.entity.iata.iata_orderreshoprs.Offer1Type offer1Type : orderReshopGetPriceResponse.getIATAOrderReshopRS().getResponse().getReshopResults().getReshopOffers().getOffer()) {
                BasicOrderInfo BasicOrderInfo = new BasicOrderInfo();
                BasicOrderInfo.offerID = offer1Type.getOfferID(); //航班变更申请id
            }
        } catch (Exception exception) {
            System.out.println(exception.getMessage());
        }
        return response;
    }

    /**
     * 获取token
     * @return
     */
    public SpringTokenResponse getToken()
    {
        String tokenUrl = this.s_JsonUrl + "auth/oauth2/accessToken";
        SpringToken springToken = new SpringToken();
        springToken.setTimestamp(DateUtils.getNowDate().getTime());
        springToken.setGrantType("SHA2");
        springToken.setAppKey(this.appkey);
        String signInfo = md5(this.appkey + springToken.getGrantType() + this.secret + springToken.getTimestamp() + this.appkey).toUpperCase();
        springToken.setSign(signInfo);
        String result = HttpClientUtil.doPostJson(tokenUrl, JSON.toJSONString(springToken));
        SpringTokenResponse springTokenResponse = JSON.parseObject(result, SpringTokenResponse.class);
        return springTokenResponse;
    }

    /**
     * 获取春秋会员信息
     * @param springMemberRequest
     * @return
     */
    public SpringMemberResponse GetSpringMember(SpringMemberRequest springMemberRequest)
    {
        SpringMemberResponse springMemberResponse = new SpringMemberResponse();
        String urlInfo = this.s_JsonUrl + "weekApiOrder/ota/orderOtaCtr/regAndActCustForDifferentTrades";
        SpringTokenResponse tokenResponse = getToken();
        if (!tokenResponse.getIfSuccess().equals("Y"))
        {
            springMemberResponse.setErrMsg("获取Token失败");
            springMemberResponse.setErrCode((EnumHelper.ReturnCode.系统异常代码).toString());
        }
        HashMap<String, String> header = new HashMap<>();
        header.put("accessToken", tokenResponse.getOauth2ResultDTO().getAccessToken());
        String result = HttpClientUtil.doPostJsonWithHeaderMap(urlInfo, JSON.toJSONString(springMemberRequest.getRegBean()), header);
        springMemberResponse = JSON.parseObject(result, SpringMemberResponse.class);
        springMemberResponse.setErrMsg(getErrorMessage(springMemberResponse.getErrCode()));
        return springMemberResponse;
    }


    /**
     * 获取错误信息
     * @param errorCode
     * @return
     */
    public String getErrorMessage(String errorCode)
    {
        String Error;
        switch (errorCode)
        {
            case "AIRSALESWS-EXCEP-001":
                Error = "数据库数据访问异常";
                break;
            case "AIRSALESWS-EXCEP-002":
                Error = " 传入的参数不符合数据格式要求";
                break;
            case "AIRSALESWS-EXCEP-100":
                Error = "当前代理客户未被授权访问该接口服务";
                break;
            case "AIRSALESWS-EXCEP-101":
                Error = "代理人密码验证不匹配";
                break;
            case "AIRSALESWS-EXCEP-102":
                Error = "当前代理客户已被关闭代理资格";
                break;
            case "AIRSALESWS-EXCEP-111":
                Error = "当前代理客户没有该订单的操作权限";
                break;
            case "ERR821-1000":
                Error = "操作成功";
                break;
            case "ERR821-1001":
                Error = "参数异常";
                break;
            case "ERR821-1002":
                Error = "取消失败，该航班变更申请不存在，或者不是“已申请”状态";
                break;
            case "ERR821-9999":
                Error = "其他异常";
                break;
            case "ERR816-1001":
                Error = "参数异常";
                break;
            case "ERR816-1013":
                Error = "新航班舱位限额不足";
                break;
            case "ERR816-1014":
                Error = "系统异常，原航班舱位限额释放失败";
                break;
            case "ERR816-1015":
                Error = "系统异常，新航班舱位销售数记录失败";
                break;
            case "ERR816-1016":
                Error = "系统异常，非法的航班变更处理方式";
                break;
            case "ERR816-1020":
                Error = "系统异常，一张机票在一个航班上占了多个选座座位";
                break;
            case "ERR816-1023":
                Error = "系统异常，原航班选座座位释放失败";
                break;
            case "ERR816-1025":
                Error = "系统异常，新航班舱位限额释放失败";
                break;
            case "ERR816-1026":
                Error = "系统异常，新航班选座座位释放失败";
                break;
            case "ERR816-9999":
                Error = "其他异常";
                break;
            case "ERR765-001":
                Error = "该变更申请不是已取消状态";
                break;
            case "ERR765-002":
                Error = "该机票不是商务座机票";
                break;
            case "ERR765-003":
                Error = "商务座限额释放失败";
                break;
            case "ERR803-082":
                Error = "特殊旅客暂时无法提供服务";  //如70岁以上老年人
                break;

            case "ERR803-001": Error = " 传入参数异常"; break;
            case "ERR803-002": Error = " 成人至少要有1个，最多只能有9个"; break;
            case "ERR803-003": Error = " 一次最多只能购买两张成人特价票"; break;
            case "ERR803-004": Error = " 传入的航段无法构成往返或连程航班"; break;
            case "ERR803-005": Error = " 旅客人数与旅客信息条数不符"; break;
            case "ERR803-006": Error = " 获取订单号异常"; break;
            case "ERR803-007": Error = " 获取机票价格失败"; break;
            case "ERR803-008": Error = " 获取机建费、燃油费失败"; break;
            case "ERR803-009": Error = " 舱位剩余数量不足，订座失败"; break;
            case "ERR803-010": Error = " 记录其他税费明细时发生异常"; break;
            case "ERR803-011": Error = " 保险预定失败"; break;
            case "ERR803-012": Error = " 预定失败，当前航班已存在姓名、证件号相同的旅客"; break;
            case "ERR803-013": Error = " 常旅客信息更新失败"; break;
            case "ERR803-016": Error = " 成人、儿童、婴儿人数不符合客规（同一订单中，在一个航班上，一个成人最多只能带两名儿童，或一名儿童和一名婴儿，如果一个成人需要携带两名婴儿，则其中至少要有一名婴儿是占座婴儿）"; break;
            case "ERR803-017": Error = " 当前舱位不可销售"; break;
            case "ERR803-018": Error = " 旅客信息解析异常"; break;
            case "ERR803-019": Error = " 部分旅客的签证到航班起飞之时已过期，不可使用"; break;
            case "ERR803-020": Error = " 订单优惠记录失败"; break;
            case "ERR803-021": Error = "当前会员已存在两个尚未支付的订单，不可再预定"; break;
            case "ERR803-022": Error = " X产品预定失败"; break;
            case "ERR803-023": Error = " 当前航线不可以预定订单"; break;
            case "ERR803-024": Error = "只有使用人民币支付的订单才可预定保险"; break;
            case "ERR803-025": Error = "组成往返、连程的航班必须是同一航空公司的航班"; break;
            case "ERR803-026": Error = " 占商务座限额处理失败"; break;
            case "ERR803-027": Error = "商务增值打包产品预定操作异常"; break;
            case "ERR803-028": Error = " 预定失败，当前预定的旅客中存在失信被执行人"; break;
            case "ERR803-029": Error = "预定失败，当前预定的旅客中存在公安敏感人员"; break;
            case "ERR803-030": Error = "目前不开放全价舱普通座销售"; break;
            case "ERR803-031": Error = "预订商务经济座机票的同时不能预订儿童或婴儿票"; break;
            case "ERR803-032": Error = "代理销售必须符合代理航班舱位销售设置"; break;
            case "ERR803-150": Error = "旅客信息不符合要求"; break;
            case "ERR803-151": Error = " 有部分旅客的类别和所填写的生日信息相矛盾"; break;
            case "ERR803-999": Error = "其他异常"; break;
            case "ERR665-001": Error = "请先输入旅客证件号"; break;
            case "ERR665-002": Error = "请先输入旅客证件号"; break;
            case "ERR665-003": Error = "请先输入旅客证件号码,如无则输入出生年月日"; break;
            case "ERR665-004": Error = "订单中存在公司暂无能力服务的旅客"; break;
            case "ERR665-005": Error = "订单中存在公安敏感人员"; break;
            case "ERR665-006": Error = "请确认订单中旅客证件号码长度"; break;
            case "ERR665-007": Error = "请确认订单中成人旅客证件号码的正确性"; break;
            case "ERR665-008": Error = "请确认订单中成人旅客证件号码的正确性"; break;
            case "ERR665-009": Error = "请确认订单中儿童旅客证件号码的正确性"; break;
            case "ERR665-010": Error = "请确认订单中儿童旅客证件号码的正确性"; break;
            case "ERR665-500": Error = "没有数据"; break;
            case "ERR665-501": Error = "请检查订单中旅客证件号码的正确性"; break;
            case "ERR665-502": Error = "其它错误"; break;
            case "ERR803-049": Error = "乘客有可能为失信被执行人，请黑屏验证"; break;
            case "TempReg": Error = "实名信息认证失败,可用临时账号下单"; break;
            case "AirSalesService-EXCEP-001": Error = "数据库数据访问异常"; break;
            case "AirSalesService-EXCEP-002": Error = "传入的参数不符合数据格式要求"; break;
            case "AirSalesService-EXCEP-003": Error = "当前接口需要用到的第三方服务不存在或不正常"; break;
            case "AirSalesService-EXCEP-004": Error = "第三方认证失败,请确认本人信息是否正确"; break;
            case "AirSalesService-EXCEP-005": Error = "手机号或者证件号认证次数超过限制"; break;
            case "AirSalesService-EXCEP-006": Error = "加解密失败"; break;
            case "AirSalesService-EXCEP-009": Error = "同一套三要素信息并发请求失败,请等待"; break;
            case "ERR915-1000": Error = "激活成功"; break;
            case "ERR915-1001": Error = "参数异常"; break;
            case "ERR915-1002": Error = "激活失败，登录账号验证不匹配"; break;
            default:
                Error = "未识别的code代码：-" + errorCode;
                break;

        }
        return Error;
    }

    private String signMsgs(String value, String keys) {
        List<Integer> kst =new ArrayList<>();
        StringBuilder builder = new StringBuilder();
        builder.append(value);
        builder.append(keys);
        String md5 = md5(builder.toString());
        md5.toLowerCase();
        return md5;
    }

    /**
     * md5加密
     *
     * @param sourceStr
     * @return
     */
    private static String md5(String sourceStr) {
        String md5Hex = DigestUtils.md5Hex(sourceStr.getBytes(StandardCharsets.UTF_8));
        return md5Hex;
    }

    public static <T> void getListGroup(List<T> lstData, List<List<T>> lstAllData, String type)
    {
        for (T data: lstData)
        {
            if (lstAllData.size() == 0)
            {
                List<T> lstTmpData = new ArrayList<>();
                lstTmpData.add(data);
                lstAllData.add(lstTmpData);
                continue;
            }
            boolean found = false;
            for (List<T> lstAll: lstAllData)
            {
                if (lstAll.stream().anyMatch(item -> ReflectUtils.getFieldValue(item, type).toString().equals(ReflectUtils.getFieldValue(data,type))))
                {
                    found = true;
                    lstAll.add(data);
                }
            }
            if (!found)
            {
                List<T> lstTmpData = new ArrayList<>();
                lstTmpData.add(data);
                lstAllData.add(lstTmpData);
            }
        }
    }
}
